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%";
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

友情鏈接更多精彩內(nèi)容