M
M
Muxto2014-03-27 00:18:43
SQL
Muxto, 2014-03-27 00:18:43

How does this SQL query work?

Hello everybody.
A long time ago I wrote a request, now I remembered it and I want to finally understand how it works.
Let there be 3 tables, two are connected through one.
table A ( id1, text1)
table B (id2, text2)
table C (id1, id2)
The query itself

select 
(select text1 from A where A.id1 = C.id1) as 'A',
(select text2 from B where B.id2= C.id2) as 'B'
from C;

How do subqueries know about table C?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
svd71, 2014-03-27
@Muxto

the main query is table C. it is the number of records in it that will be displayed in the selection. and columns text1 and text2 are pulled out from subqueries to tables B and A. And those, in turn, will take values ​​for searching from the main query, that is, from table C.

M
Muxto, 2014-03-30
@Muxto

According to SQL-92
1. FROM is executed - a work table is formed
2. WHERE clause predicates are applied to this result
3. GROUP By
4. HAVING
5. SELECT
6. ORDER BY (not formally part of the SELECT definition)
(C) Joe Celko. SQL for professionals. Programming.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question