Limit results with WHERE

If you're interested only in the title Classic Shell Scripting, you can use a WHERE clause to restrict your query:

SELECT * FROM books WHERE title = "Classic Shell Scripting";

This returns:

| title_id | title | pages | +----------+-------------------------+-------+

| 2 | Classic Shell Scripting | 256 | +----------+-------------------------+-------+

1 row in set (0.00 sec) You can also list out just the columns you're interested in from a table by using:

SELECT books.pages FROM books WHERE title = "Classic Shell Scripting"; This returns:

Conditions come after the WHERE clause. More than one condition can be specified using logical operators such as AND and OR. Parentheses () can be used to modify the preference of the logical operators. At some point, you might want to display data from multiple tables in a query.

You should also get into the habit of referencing columns as TABLE.COLUMN. This prevents confusion when selecting columns if both tables have a column with the same name. For example, if two tables include a description field, it may not be clear which description to include in the query unless the full reference is included.

Was this article helpful?

0 0

Post a comment