Video Tutorial 10 SQL. Subselects (Subqueries) with MySql Workbench

A Subquery or Subselect or inner query is a query inside another SQL query, and embedded within the WHERE clause.

It is used to return data that will be used in the main query as a condition to further restrict the data to be retrieved.

SUBQUERIES SYNTAX

Subqueries are most frequently used with the SELECT statement.

The basic syntax is as follows:

SELECT column_name [, column_name ]  
FROM   table1 [, table2 ] 
WHERE  column_name OPERATOR        
	(SELECT column_name [, column_name ] 
	FROM table1 [, table2 ] 
	[WHERE])

SUBQUERIES EXAMPLE

This is our table "authors";

We are going to select the youngest author using the following subquery;

SELECT * FROM eli.authors where birthday= (select max(birthday) from eli.authors);

And this is our result;

If you are interested in more complicated examples, please watch the video tutorial on this page.

<< Previous Next >>