Home > Articles > Data > MySQL

  • Print
  • + Share This
This chapter is from the book

Summary

The SELECT SQL command is used to retrieve records from specific tables. The * character allows you to easily select all fields for all records in a table, but you can also specify particular column names. If the result set is too long, the LIMIT clause provides a simple method for extracting slices of results if you indicate a starting position and the number of records to return.

To order the results, use the ORDER BY clause to select the columns to sort. Sorts can be performed on integers, dates, and strings, in either ascending or descending order. The default order is ascending. Without specifying an order, results are displayed in the order they appear in the table.

Using built-in functions like COUNT(), MIN(), and MAX(), you can gather more information about the tables and records besides the data in them. COUNT() will return the count of a column, and MIN() and MAX() return the minimum and maximum values for a column.

You can pick and choose which records you want to return using WHERE clauses to test for the validity of conditions. Comparison or logical operators are used in WHERE clauses, and sometimes both types are used for compound statements. Another type of operator is LIKE, used for string comparisons.

  • + Share This
  • 🔖 Save To Your Account