main logo
Subject: SELECT the right sequence?
Author: Luca Porfiri
Posted: 2002/05/30 04:38:26
 
View Entire Thread
New Search


Hy all!

Could someone help me to understand the meaning?

This is the structure of sql string:

---------------------

SELECT *

FROM table_1, table_2

WHERE

field_1.table_1 = "x"
AND
field_1.table_2 = field_2.table_1
AND
field_2.table_2 = "y"
AND
field_3.table_1 = "z"
---------------------


now, this structure find for occurrences as the first statement of WHERE
(field_1.table_1 = "x")
was absent
so it searches and find as I wrote:

---------------------

SELECT *

FROM table_1, table_2

WHERE

field_1.table_2 = field_2.table_1
AND
field_2.table_2 = "y"
AND
field_3.table_1 = "z"
---------------------


the same if I put the last statement at beginning substituting that one.

BUT

if I put statement searching for x and z at beginning as in :

SELECT *

FROM table_1, table_2

WHERE

field_1.table_1 = "x"
AND
field_3.table_1 = "z"
AND
field_1.table_2 = field_2.table_1
AND
field_2.table_2 = "y"

alla works fine!

-----
FINALLY if the sequence is

SELECT *

FROM table_1, table_2

WHERE


field_1.table_2 = field_2.table_1
AND
field_2.table_2 = "y"
AND
field_1.table_1 = "x"
AND
field_3.table_1 = "z"

it will search and find as the last query didn't exist. alias it considers
anly the first statement after searching in table_2

What's the rule?

THANKS!
 
©2002 Luca Porfiri
<-- Prior Message New Search Next Message -->