SQL query execution order

 ليه لازم تفهم دة

عشان لما ت Run حاجة زي دي تفهم ايه الغلط



________

 : Query 1

SELECT first_name +' '+ last_name AS full_name

FROM students

ORDER BY full_name

_____________________________

 : Query 2

SELECT first_name +' '+ last_name AS full_name

FROM students

'WHERE full_name = 'Omar Khaled

____________________________

ال Error هيجي من Query 2
ليه
تعالي نحلل Query 1 الاول
_____
اول حاجة في Query دي بتتنذف FROM بيشوف فين الداتا
بعدها ال SELECT
ف هنا هو شاف انه في حاجة اسمها full_name اتعملت في ال run time
فا مش هيعترض اما يشوفها في ORDER BY الي هي اخر حاجة بتتنفذ هنا


___________
لكن في QUERY 2
اول حاجة في Query دي بتتنذف FROM بيشوف فين الداتا
بعدها بينفذ ال WHERE
هنا هيقول انا معنديش حاجة اسمها full_name
لان الترتيب ان ال WHERE بتتنفذ بدري عن ال SELECT
__________
الترتيب كالاتي

FROM
JOIN
ON
بيشوف هو الداتا فين
WHERE
GROUP BY
HAVING - AGG
بعدها يفلترها

SELECT - DISTINCT + AGG
ORDER BY
TOP

Comments

Popular posts from this blog

Managing Null Values in Your Data Warehouse: Key Considerations

What is data science

Choosing Between Alternate Key (Business Key) and Surrogate Key for Foreign Keys in the Fact Table: A Guide

A Comprehensive Guide to CSV Files vs. Parquet Files in PySpark

بداية مذاكرتك لل Data analysis