The SELECT command in MySQL allows you to examine rows in a table (or more than one table if you like). Good news - but sometimes there's an awful lot of data and you just want rows chosen by particular criteria, or just the first (so many) rows.
The WHERE clause on your select allows you to write a number of conditions which can be linked with AND and OR keywords, and there's a great deal of choice in the conditions. Here are some examples:
WHERE name = "Graham"
Will look for the string Graham (exactly) and nothing else in the field called name. Note that this selection is case sensitive if name is specified as being a binary field, and case insensitive otherwise.
WHERE name IN ("Graham","Lisa","Leah")
Will look for any one of the strings Graham Lisa or Leah (exactly in each case; same rule about case as in the example above).
WHERE name LIKE "%Graham%"
Will return any row that contains the word Graham within the name field. This is similar to file name matching (also known as globbing) except that the % metacharacter means "anything" and the _ character (that's an underscore) means any one character ... in place of * and ? in file name matching.
WHERE name RLIKE "^[[:graph:]]+$"
Will return any row with a single name in the name field - this is a regular expression which provides a huge flexibility in matching. Regular Expressions are notable in that you can ask a lot in a very obtuse string of just a few characters!
(written 2005-11-22, updated 2006-06-05)
Associated topics are indexed under
S152 - SQL Primer as Used in MySQL [3061] Databases - why data is split into separate tables, and how to join them - (2010-11-20)
[3060] INSERT, DELETE, REPLACE and UPDATE - changing the content of SQL tables - (2010-11-19)
[2240] How do I query a database (MySQL)? - (2009-06-15)
[591] Key facts - SQL and MySQL - (2006-02-04)
[515] MySQL - an FAQ - (2005-12-03)
[494] MySQL - a score of things to remember - (2005-11-12)
[270] NULL in MySQL - (2005-04-06)
[158] MySQL - LEFT JOIN and RIGHT JOIN, INNER JOIN and OUTER JOIN - (2004-12-20)
S157 - More MySQL commands [3270] SQL - Data v Metadata, and the various stages of data selection - (2011-04-29)
[2647] Removing duplicates from a MySQL table - (2010-02-22)
[2645] Optimising and caching your MySQL enquiries - (2010-02-22)
[2644] Counting rows in joined MySQL tables - (2010-02-22)
[2643] Relating tables with joins in MySQL - (2010-02-21)
[2448] MySQL - efficiency and other topics - (2009-10-10)
[2259] Grouping rows for a summary report - MySQL and PHP - (2009-06-27)
[2110] MySQL - looking for records in one table that do NOT correspond to records in another table - (2009-03-31)
[1904] Ruby, Perl, Linux, MySQL - some training notes - (2008-11-23)
[1735] Finding words and work boundaries (MySQL, Perl, PHP) - (2008-08-03)
[1574] Joining MySQL tables revisited - finding nonmatching records, etc - (2008-03-15)
[1331] MySQL joins revisited - (2007-09-03)
[1235] Outputting numbers as words - MySQL with Perl or PHP - (2007-06-17)
[1213] MySQL - the order of clauses and the order of actions - (2007-06-01)
[673] Helicopter views and tartans - (2006-04-06)
[581] Saving a MySQL query results to your local disc for Excel - (2006-01-29)
[572] Giving the researcher power over database analysis - (2006-01-22)
[567] Combining similar rows from a MySQL database select - (2006-01-17)
[517] An occasional chance, and reducing data to manageable levels - (2005-12-04)
[513] MySQL - JOIN or WHERE to link tables correctly? - (2005-12-01)
[449] Matching in MySQL - (2005-09-24)
[279] Getting a list of unique values from a MySQL column - (2005-04-14)
[159] MySQL - Optimising Selects - (2004-12-21)
Some other Articles
What are DHCP and DNS?Would you steal ... petrol? ... a training course?We are about Open Source programming courses in the UK10 years C# knowledge pleaseSELECT in MySQL - choosing the rows you want.css - using PHP to make dynamic style sheetsBowerhill, Melksham, 2006 CalendarGood IT training cannot be cheapWhy is Tomcat called Tomcat?I have a river to cross