MySQL Queries



Retrieving Data from a Table


Now that we know how to put data into the database, we need to learn how to get it out. When trying to access the data in a table, we use the MySQL SELECT statement. SELECT statments can be very simple or very complex. Below are the basics of the SELECT statement.
SELECT * FROM tblName;  //selects all rows from the table
SELECT fieldName1 FROM tblName;  //selects only 1 column of information from a table
SELECT fieldName1, fieldName2 FROM tblName;  //selects 2 distinct columns of info from a table
The SELECT command can be modified using the following commands: All of these query modifiers can be used in the same statement, but must be used in the correct order:
SELECT [COUNT|SUM|AVG][DISTINCT] colList from tblName WHERE [NOT] clause [AND|OR secondClause] ORDER BY colName [ASC|DESC] [LIMIT value]