Wildcard characters are used with the SQL LIKE operator. The LIKE operator is used in a WHERE clause to search for a specified pattern in a column. (we have seen use of wildcard characters during sql like keyword)
The IN operator allows you to specify multiple values in a WHERE clause.
SELECT column_name(s) FROM table_name WHERE column_name IN (value1, value2, ...);
The BETWEEN operator selects values within a given range. The values can be numbers, text, or dates.
SELECT column_name(s) FROM table_name WHERE Date BETWEEN value1 AND value2;
SELECT * FROM Products WHERE Price NOT BETWEEN 10 AND 20;
SQL aliases are used to give a table, or a column in a table, a temporary name.
Aliases are often used to make column names more readable, An alias only exists for the duration of the query.
SELECT column_name AS alias_name FROM table_name;
The PRIMARY KEY constraint uniquely identifies each record in a table.
Primary keys must contain UNIQUE values, and cannot contain NULL values.
A table can have only ONE primary key
The FOREIGN KEY constraint is used to prevent actions that would destroy links between tables.
A FOREIGN KEY is a field in one table, that refers to the PRIMARY KEY in another table.
The table with the foreign key is called the child table, and the table with the primary key is called the referenced or parent table.EmployeeID (Primary Key) | LastName | FirstName | Age |
---|---|---|---|
1 | ABC | DEF | 30 |
2 | GHI | JKL | 23 |
3 | MNO | PQR | 20 |
OrderID | OrderNumber | EmployeeID (Foreign Key) |
---|---|---|
1 | 77895 | 3 |
2 | 44678 | 3 |
3 | 22456 | 2 |
4 | 24562 | 1 |
A JOIN clause is used to combine rows from two or more tables, based on a related column between them.
SELECT Orders.OrderID, Customers.CustomerName, Orders.OrderDate FROM Orders INNER JOIN Customers ON Orders.CustomerID=Customers.CustomerID;
Here are the different types of the JOINs in SQL