SELECT will probably be your most-used SQL statement. SELECT is used whenever you want to get data from the database tables. SELECT has many modifiers and options available. We’ll show some simple SELECT statements here to get you started.
To get all books by the publisher “Wiley,” do something like this:
SELECT * FROM library WHERE publisher = ‘Wiley’;
The * means to return all of the fields. If you want only the titles and the prices, do something like this:
SELECT title, price FROM library WHERE publisher = ‘Wiley’;
If you want the results to be sorted alphabetically, do this:
SELECT title, price FROM library WHERE publisher = ‘Wiley’ ORDER BY(title);
SELECT can be a very powerful SQL statement. There are also mathematical arguments such as SUM and AVG, sorting arguments, and many more. Take a look at the MySQL documentation to get a complete understanding of the SELECT statement’s capabilities.
SELECT AVG(price) FROM library;
Returns the average price of all of the books in the library table.