FROM clause in MySQL

MySQL FROM In MySQL, the FROM clause is used with the MySQL SELECT statement to specify the table for the records to be retrieved.

Syntax: To select all fields from a table.

SELECT * FROM table_name;

Example: Selecting all fields from a table.

SELECT * FROM items;

Output:

ID NAME QUANTITY
1 Electronics 30
2 Sports 45
3 Fashion 100
4 Grocery 90
5 Toys 50

 

Syntax: To select specific fields from a table.

SELECT expressions  
FROM table_name
WHERE conditions;

Parameters:

conditions: It is used to specify the conditions to be strictly followed for selection.

Example: Selecting specific fields from a table.

SELECT *  
FROM items  
WHERE  id > 3;

Output:

ID NAME QUANTITY
4 Grocery 90
5 Toys 50

 

Syntax: To select specific fields from multiple tables.

SELECT expressions  
FROM table1
INNER JOIN table2 
ON join_predicate;

Parameters:

join_predicate: It is used to specify the condition for joining tables.

Example: Selecting specific fields from multiple tables. Items Table:

ID NAME QUANTITY
1 Electronics 30
2 Sports 45
3 Fashion 100
4 Grocery 90
5 Toys 50

Shops Table:

ID SHOP
1 A
2 B
3 C
4 D
SELECT items.quantity, shops.shop
FROM items  
INNER JOIN shops  
ON items.id = shops.id  
ORDER BY quantity;

Output:

QUANTITY SHOP
30 A
45 B
90 C
100 D
Please follow and like us:
Content Protection by DMCA.com