fastread homefastrread library fastread menu

MariaDB : FROM Clause

Tutorial by:      Date: 2016-04-18 04:58:38

❰ Previous Next ❱

This MariaDB tutorial explains how to use the MariaDB FROM clause with syntax and examples.

Description

The MariaDB FROM clause is used to list the tables and any join information required for the query.

Syntax

The syntax for the FROM clause in MariaDB is:

FROM table1

[ { INNER JOIN

  | LEFT [OUTER] JOIN

  | RIGHT [OUTER] JOIN } table2

ON table1.column1 = table2.column1 ]

Parameters or Arguments

table1 and table2

The tables used in the MariaDB statement. The two tables are joined based on table1.column1 = table2.column1.

Note

  • When using the FROM clause in a MariaDB statement, there must be at least one table listed in the FROM clause.
  • If there are two or more tables listed in the MariaDB FROM clause, these tables are generally joined using INNER or OUTER joins, as opposed to the older syntax in the WHERE clause.

Example - With one table

Let's look at how to use the FROM clause to list one table in a query in MariaDB.

For example:

SELECT *

FROM sites

WHERE site_name = 'Fastread.aitechtonic.com'

ORDER BY site_id ASC;

In this FROM clause example, we've listed only one table called sites. Since there is only one table involved in this example, there is no join information to include in the FROM clause.

Example - Multiple tables with INNER JOIN

Let's look at how to use the FROM clause to list with multiple tables and information about an INNER JOIN.

For example:

SELECT pages.page_id, sites.site_name

FROM sites

INNER JOIN pages

ON sites.site_id = pages.site_id

WHERE sites.site_name = 'Fastread.aitechtonic.com'

ORDER BY pages.page_id;

This MariaDB FROM clause example uses the FROM clause to list two tables - sites and pages. This example also includes join information in the FROM clause where we specify an INNER JOIN between the sites and pages tables based on the site_id column in both tables.

Example - Multiple Tables with OUTER JOIN

Let's look at how to use the FROM clause to list multiple tables and information about a LEFT OUTER JOIN.

For example:

SELECT sites.site_id, servers.server_name

FROM sites

LEFT OUTER JOIN servers

ON sites.site_id = servers.site_id

WHERE sites.site_name in ('Fastread.aitechtonic.com', 'CheckYourMath.com')

ORDER BY servers.server_name DESC;

This FROM clause example uses the FROM clause to list two tables - sites and servers. This example also includes join information in the FROM clause where we specify a LEFT OUTER JOIN between the sites and servers tables based on the site_id column in both tables.

 

❰ Previous Next ❱


MariaDB

Submit Your Thought, Tutorial, Articls etc.

Submit Your Information India's Number one online promotion website