MySQL has several data types, most notably:
For our purposes, we need only focus on the INTEGER type, the DOUBLE, and the DECIMAL
For our purposes, we will focus on the VARCHAR type, the TEXT type, and the BLOB type
In MySQL, there are several variables to deal with date and time.
Remember that for some data types, like DECIMAL, VARCHAR, and TIMESTAMP, you’ll need to also specify related information in the “Length/Values” field in PhpMyAdmin when you create these fields.
SQL stands for Structured Query Language and was developed by IBM. All relational databases understand statements made using SQL. You can do a lot with a little in SQL, and the four main commands we will focus on is INSERT, UPDATE, SELECT, and DELETE.
The insert statement is used to put new records into the table.
INSERT INTO table1(column1,..) VALUES (expression,...)
so for example; in our recording table:
INSERT INTO recording (id, title) VALUES (1, 'Hello, Nasty')
Note that numeric values do not need quotes to delineate them, but string values do. Also, if your string has a single quote ' in it, you must escape it by adding another single quote:
INSERT INTO recording (title) VALUES ('Don''t Fear The Reaper')
The UPDATE statement is used to modify any existing records in your table. Here is the format of the UPDATE statement:
UPDATE TABLE SET column1=expression1, column2=expression2, ... [WHERE "conditions"]
So, for example, in our recording table:
UPDATE recording SET title='The White Album' WHERE title='White Album'
or
UPDATE recording SET title='OK, Computer' WHERE id=3
The SELECT statement is used to query the database and retrieve selected data that match whatever criteria you specify. It has five main clauses, and FROM is the only required clause.
Here is the format of the SELECT statement:
SELECT [DISTINCT] column1[,column2] FROM table1[,table2] [WHERE "conditions"] [GROUP BY "column-list" [ASC | DESC] ] [HAVING "conditions] [ORDER BY "column-list" [ASC | DESC] ] [LIMIT [offset,] number-rows]
Often, you only need a simpler version of this:
SELECT column1 FROM table1 WHERE "conditions"
Example:
SELECT id FROM recording WHERE title = "Hello, Nasty"
The above statement will select all of the values in the id column from the recording table for recording whose title is “Hello, Nasty”. If you use an * for which columns you want, it acts as wildcard and gets all of the columns:
SELECT * FROM recording WHERE title = "Hello, Nasty"
| = | Equal |
| > | Greater than |
| < | Less than |
| >= | Greater than or equal to |
| ⇐ | Less than or equal to |
| <> or != | Not equal to |
| LIKE | String comparison test |
Example:
SELECT id, title FROM recording WHERE title LIKE ‘Hello%’;
The above statement selects the ID and title of every recording that beings with ‘Hello’. In our case, it will return “Hello, Nasty” and its ID.
DISTINCT is a keywords used to obtain only the “distinct” or unique records in your query results. DISTINCT will discard the duplicate records for the columns you specified after the “SELECT” statement: For example, suppose one of our fields in recording was “release_year”, which is the year of the recording’s release date. We could say:
SELECT DISTINCT release_year FROM recording
which would return all of the unique release years in the recording table. Thus, if two recordings were released in the same year, that year would only show up once in our results.
The DELETE statement The DELETE statement is remove specific records from your table. Here is the format of the INSERT statement:
DELETE FROM table1 [WHERE "conditions"]
So, for example, to delete just the “Hello, Nasty” entry in our recording table, we would say:
DELETE FROM recording WHERE title='Hello,Nasty'
If you wanted to delete everything from the recording table:
DELETE FROM recording