The SELECT statement allows you to retrieve records from one or more tables in your database.
The syntax for the SELECT statement is:
For example:
The syntax for the SELECT statement is:
SELECT columns
FROM tables
WHERE predicates;
FROM tables
WHERE predicates;
Example #1:
Let's take a look at how to select all fields from a table.SELECT *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.
FROM suppliers
WHERE city = 'Newark';
Example #2:
You can also choose to select individual fields as opposed to all fields in the table.For example:
SELECT name, city, stateThis select statement would return all name, city, and state values from the suppliers table where the supplier_id value is greater than 1000.
FROM suppliers
WHERE supplier_id > 1000;
Example #3:
You can also use the select statement to retrieve fields from multiple tables.SELECT orders.order_id, suppliers.nameThe result set would display the order_id and supplier name fields where the supplier_id value existed in both the suppliers and orders table.
FROM suppliers, orders
WHERE suppliers.supplier_id = orders.supplier_id;
0 comments:
Post a Comment