Category Archives: MYSQL COMMANDS

SQL IN

SQL IN
The SQL IN clause allows you to specify discrete values in your SQL WHERE search criteria.
THE SQL IN syntax looks like this:

SELECT Column1, Column2, Column3, …
FROM Table1
WHERE Column1 IN (Valu1, Value2, …)

SQL ORDER BY

The SQL ORDER BY clause comes in handy when you want to sort your SQL result sets by some column(s).
SQL keyword after your SQL ORDER BY clause:

SELECT * FROM tbl_name
ORDER BY Column_name DESC/Asc

SQL UPDATE

The SQL UPDATE general syntax looks like this:

UPDATE Table1
SET Column1 = Value1, Column2 = Value2
WHERE Some_Column = Some_Value
The SQL UPDATE clause changes the data in already existing database row(s) and usually we need to add a conditional SQL WHERE clause to our SQL UPDATE statement in order to specify which row(s) we intend to update.

SQL INSERT INTO

The SQL INSERT INTO syntax has 2 main forms and the result of either of them is adding a new row into the database table.
The first syntax form of the INSERT INTO SQL clause doesn’t specify the column names where the data will be inserted, but just their values:

INSERT INTO Table1
VALUES (value1, value2, value3…)
The second form of the SQL INSERT INTO command, specifies both the columns and the values to be inserted in them:

INSERT INTO Table1 (Column1, Column2, Column3…)
VALUES (Value1, Value2, Value3…)
As you might already have guessed, the number of the columns in the second INSERT INTO syntax form must match the number of values into the SQL statement, otherwise you will get an error.
If we want to insert a new row into our Customers table, we are going to use one of the following 2 SQL statements:

INSERT INTO Customers
VALUES (‘Peter’, ‘Hunt’, ‘peter.hunt@tgmail.net’, ‘1/1/1974’, ‘626 888-8888’)

INSERT INTO Customers (FirstName, LastName, Email, DOB, Phone)
VALUES (‘Peter’, ‘Hunt’, ‘peter.hunt@tgmail.net’, ‘1/1/1974’, ‘626 888-8888’)