SQL | The BETWEEN Operator

SQL Webp

BETWEEN Operator Example The “Persons” table: Now we want to select the persons with a last name alphabetically between “Hansen” and “Pettersen” from the table above. We use the following SELECT statement: The result-set will look like this: P_Id LastName FirstName Address City1 Hansen Ola Timoteivn 10 Sandnes The BETWEEN operator is treated differently in … Read more

SQL | The IN Operator

SQL Webp

The IN operator allows you to specify multiple values in a WHERE clause. SQL IN Syntax: IN Operator Example The “Persons” table: Now we want to select the persons with a last name equal to “Hansen” or “Pettersen” from the table above. We use the following SELECT statement: The result-set will look like this:

SQL | The LIKE Operator

SQL Webp

SELECT column_name(s) FROM table_name WHERE column_name LIKE pattern LIKE Operator Example The “Persons” table: Now we want to select the persons living in a city that starts with “s” from the table above. We use the following SELECT statement: SELECT * FROM Persons WHERE City LIKE ‘s%’ The “%” sign can be used to define … Read more

SQL ADVANCE | The TOP Clause

SQL Webp

SELECT TOP number|percent column_name(s) FROM table_name SQL SELECT TOP Equivalent in MySQL and Oracle: MySQL Syntax: SELECT column_name(s) FROM table_name LIMIT number Example: SELECT * FROM Persons LIMIT 5 Oracle Syntax SELECT column_name(s) FROM table_name WHERE ROWNUM <= number Example SELECT * FROM Persons WHERE ROWNUM <=5 SQL TOP Example The “Persons” table: Now we … Read more

SQL | The DELETE Statement

SQL Webp

DELETE FROM table_name WHERE some_column=some_value Note: Notice the WHERE clause in the DELETE syntax. The WHERE clause specifies which record or records that should be deleted. If you omit the WHERE clause, all records will be deleted! SQL DELETE Example The “Persons” table: Now we want to delete the person “Tjessem, Jakob” in the “Persons” … Read more