Archive:PHP and MySQL Programming/Basic Queries: Difference between revisions

Line 9: Line 9:
The SELECT query is the standard means by which to retrieve information from the database. The syntax for the SELECT query is as follows:
The SELECT query is the standard means by which to retrieve information from the database. The syntax for the SELECT query is as follows:


  mysql> SELECT `field1`, `field2`, ...  
  mysql> SELECT field1, field2, ...  
         FROM `table_name`
         FROM table_name
         [WHERE condition1
         [WHERE condition1
             AND condition2
             AND condition2
             ...
             ...
         [ORDER BY `field1`, `field2`, etc...]
         [ORDER BY field1, field2, etc...]
         [LIMIT number]];
         [LIMIT number]];


Example :  
Example :  


  mysql> SELECT * FROM `books`;
  mysql> SELECT * FROM books`;
   
   
  mysql> SELECT `Title`, `Author`
  mysql> SELECT Title, Author`
         FROM `books`
         FROM books`
         WHERE `Year` > 2001
         WHERE Year > 2001
         AND `Year` < 2006
         AND Year < 2006
         ORDER BY `Author`
         ORDER BY Author ASC
         LIMIT 100;
         LIMIT 100;