Preamble
MySQL FROM statement is used to display tables and any associations required for querying in MySQL.
Syntax of FROM statement in MySQL
FROM table1
[ { INNER JOIN
| LEFT [OUTER] JOIN
| RIGHT [OUTER] JOIN } table2
ON table1.column1 = table2.column1 ]
Statement parameters and arguments
- table1 and table2 are tables used in MySQL sentence. These two tables are combined based on table1.column1 = table2.column1.
Note:
- When using the FROM operator in a MySQL sentence, there should be at least one table listed in the FROM operator.
- If there are two or more tables listed in MySQL in the FROM statement, these tables are usually combined using INNER or OUTER connections, unlike the old WHERE syntax.
How to use the MySQL FROM statement
Let’s start by looking at how to use the FROM statement with only one table.
For example:
SELECT *
FROM order_details
WHERE quantity >= 100
ORDER BY DESC;
In this MySQL example, we used the FROM operator to list all columns of a table named order_details. No associations are executed because we use only one table.
Two tables with INNER JOIN
Let’s see how to use the FROM operator with two tables and an INNER JOIN.
For example:
SELECT order_details.order_id, customers.customer_name
FROM customers
INNER JOIN order_details
ON customers.customer_id = order_details.customer_id
ORDER BY order_details.order_id;
In this MySQL example, the FROM statement is used to display two tables, customers, and order_details. And we use the FROM statement to combine INNER JOIN between customers and order_details tables based on the customer_id column in both tables.
Two tables with OUTER JOIN
Let’s look at how to use the FROM operator when we combine two tables together using OUTER JOIN. In this case, we will look at the LEFT OUTER JOIN.
For example:
SELECT products.product_id, inventory.qty_on_hand
FROM products
LEFT OUTER JOIN inventory
ON products.product_id = inventory.product_id
WHERE products.product_name = 'MySQL';
In this MySQL example, the FROM operator is used to list two tables, products, and inventory. And we use the FROM statement to specify the LEFT OUTER JOIN between the product and inventory tables based on the product_id columns in both tables.
Learning MySQL; SELECT Statements
About Enteros
Enteros offers a patented database performance management SaaS platform. It proactively identifies root causes of complex business-impacting database scalability and performance issues across a growing number of clouds, RDBMS, NoSQL, and machine learning database platforms.
The views expressed on this blog are those of the author and do not necessarily reflect the opinions of Enteros Inc. This blog may contain links to the content of third-party sites. By providing such links, Enteros Inc. does not adopt, guarantee, approve, or endorse the information, views, or products available on such sites.
Are you interested in writing for Enteros’ Blog? Please send us a pitch!
RELATED POSTS
Maximizing ROI with Enteros: Cloud FinOps Strategies for Reserved Instances and Database Optimization
- 28 November 2024
- Database Performance Management
In the fast-evolving world of finance, where banking and insurance sectors rely on massive data streams for real-time decisions, efficient anomaly man…
Revolutionizing Healthcare with RevOps: Integrating Cloud FinOps, AIOps, and Observability Platforms for Operational Excellence
In the fast-evolving world of finance, where banking and insurance sectors rely on massive data streams for real-time decisions, efficient anomaly man…
Enhancing Accountability and Cost Estimation in the Financial Sector with Enteros
- 27 November 2024
- Database Performance Management
In the fast-evolving world of finance, where banking and insurance sectors rely on massive data streams for real-time decisions, efficient anomaly man…
Optimizing E-commerce Operations with Enteros: Leveraging Enterprise Agreements and AWS Cloud Resources for Maximum Efficiency
In the fast-evolving world of finance, where banking and insurance sectors rely on massive data streams for real-time decisions, efficient anomaly man…