SQL Trainer

1. View available tables
Database contains one or more tables. Each table has a name. In some popular databases like MySQL and others you may get the list of available tables just by typing:

SHOW tables;

2. View content with all columns and rows in a given table
Every database contains one or more tables. In this SQL trainer we have 2 tables: orders and customers.
Each table has rows and columns. You may see all columns from selected table with a query that uses * symbol, like this :

SELECT * FROM mytable;

3. View one selected column only
The most widely used SQL query is for viewing selected columns from a table. For example, you may view only name from customers table with this query:

SELECT name FROM customers;

4. Get multiple columns from table
You may also view few columns at time! Just list them with comma. For example, you may view size and price from orders using this query:

SELECT size, price FROM orders;

5. Limit number of results
You may have thousands of records but need to view only 10 first records. You may limit number of records using LIMIT keyword

SELECT * FROM orders LIMIT 5;

6. Another keyword to filter results: TOP command
Some databases use TOP keyword instead of LIMIT. This keyword also limits the number of results to a given number and it is used a bit differently like this:

SELECT TOP 5 * FROM orders;

7. Find records by a partial string
You may search data using wildcard operators that makes it easy to find all matching records in a large table of thousands of records. The keyword LIKE helps with this and % symbol is used as a wildcard that can be at the left or right or both. The query below will search for all names starting 'Mike':

SELECT * FROM companies WHERE ceo LIKE "Mike%";

你可能感兴趣的:(SQL Trainer)