SQL: SELECT Statement
The SELECT statement allows you to retrieve records from one or more tables in your database.
The syntax for the SELECT statement is:
Let's take a look at how to select all fields from a table.
WHERE city = 'Newark';
In our example, we've used * to signify that we wish to view all fields from the suppliers table where the supplier resides in Newark.
You can also choose to select individual fields as opposed to all fields in the table.
SELECT name, city, state
WHERE supplier_id > 1000;
This select statement would return all name, city, and state values from the suppliers table where the supplier_id value is greater than 1000.
You can also use the select statement to retrieve fields from multiple tables.
SELECT orders.order_id, suppliers.name
FROM suppliers, orders
WHERE suppliers.supplier_id = orders.supplier_id;
The result set would display the order_id and suppier name fields where the supplier_id value existed in both the suppliers and orders table.