Is there any specific order of execution in SQL query?
up vote
0
down vote
favorite
I am confused about the execution order of SQL queries.
For example, (Inner join in MySQL in the code below), between WHERE clause and SELECT * FROM clause, which one gets to be interpreted and executed first?
That is to say, does the query below bring *(all) of the tables data first then find the cases that match with WHERE condition? or Do they just find the list of data that match with WHERE condition and then SELECT * FROM from the WHERE result?
SELECT * FROM customers, orders
WHERE customers.id = orders.customer_id;
As above case, I am wondering how the SQL queries are executed in general.
mysql sql inner-join
add a comment |
up vote
0
down vote
favorite
I am confused about the execution order of SQL queries.
For example, (Inner join in MySQL in the code below), between WHERE clause and SELECT * FROM clause, which one gets to be interpreted and executed first?
That is to say, does the query below bring *(all) of the tables data first then find the cases that match with WHERE condition? or Do they just find the list of data that match with WHERE condition and then SELECT * FROM from the WHERE result?
SELECT * FROM customers, orders
WHERE customers.id = orders.customer_id;
As above case, I am wondering how the SQL queries are executed in general.
mysql sql inner-join
5
periscopedata.com/blog/sql-query-order-of-operations
– scaisEdge
Nov 4 at 17:45
1
The whole point of languages like SQL is for you to describe (logically) what you want, and to leave it up to the optimizer about how best to produce that result. That's why e.g. execution order is far more loosely defined with SQL than with many procedural languages.
– Damien_The_Unbeliever
Nov 4 at 18:32
Possible duplicate of What's the execute order of the different parts of a SQL select statement?
– philipxy
Nov 4 at 19:03
See How to Ask. Please research.
– philipxy
Nov 4 at 19:04
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I am confused about the execution order of SQL queries.
For example, (Inner join in MySQL in the code below), between WHERE clause and SELECT * FROM clause, which one gets to be interpreted and executed first?
That is to say, does the query below bring *(all) of the tables data first then find the cases that match with WHERE condition? or Do they just find the list of data that match with WHERE condition and then SELECT * FROM from the WHERE result?
SELECT * FROM customers, orders
WHERE customers.id = orders.customer_id;
As above case, I am wondering how the SQL queries are executed in general.
mysql sql inner-join
I am confused about the execution order of SQL queries.
For example, (Inner join in MySQL in the code below), between WHERE clause and SELECT * FROM clause, which one gets to be interpreted and executed first?
That is to say, does the query below bring *(all) of the tables data first then find the cases that match with WHERE condition? or Do they just find the list of data that match with WHERE condition and then SELECT * FROM from the WHERE result?
SELECT * FROM customers, orders
WHERE customers.id = orders.customer_id;
As above case, I am wondering how the SQL queries are executed in general.
mysql sql inner-join
mysql sql inner-join
asked Nov 4 at 17:42
Poream3387
369112
369112
5
periscopedata.com/blog/sql-query-order-of-operations
– scaisEdge
Nov 4 at 17:45
1
The whole point of languages like SQL is for you to describe (logically) what you want, and to leave it up to the optimizer about how best to produce that result. That's why e.g. execution order is far more loosely defined with SQL than with many procedural languages.
– Damien_The_Unbeliever
Nov 4 at 18:32
Possible duplicate of What's the execute order of the different parts of a SQL select statement?
– philipxy
Nov 4 at 19:03
See How to Ask. Please research.
– philipxy
Nov 4 at 19:04
add a comment |
5
periscopedata.com/blog/sql-query-order-of-operations
– scaisEdge
Nov 4 at 17:45
1
The whole point of languages like SQL is for you to describe (logically) what you want, and to leave it up to the optimizer about how best to produce that result. That's why e.g. execution order is far more loosely defined with SQL than with many procedural languages.
– Damien_The_Unbeliever
Nov 4 at 18:32
Possible duplicate of What's the execute order of the different parts of a SQL select statement?
– philipxy
Nov 4 at 19:03
See How to Ask. Please research.
– philipxy
Nov 4 at 19:04
5
5
periscopedata.com/blog/sql-query-order-of-operations
– scaisEdge
Nov 4 at 17:45
periscopedata.com/blog/sql-query-order-of-operations
– scaisEdge
Nov 4 at 17:45
1
1
The whole point of languages like SQL is for you to describe (logically) what you want, and to leave it up to the optimizer about how best to produce that result. That's why e.g. execution order is far more loosely defined with SQL than with many procedural languages.
– Damien_The_Unbeliever
Nov 4 at 18:32
The whole point of languages like SQL is for you to describe (logically) what you want, and to leave it up to the optimizer about how best to produce that result. That's why e.g. execution order is far more loosely defined with SQL than with many procedural languages.
– Damien_The_Unbeliever
Nov 4 at 18:32
Possible duplicate of What's the execute order of the different parts of a SQL select statement?
– philipxy
Nov 4 at 19:03
Possible duplicate of What's the execute order of the different parts of a SQL select statement?
– philipxy
Nov 4 at 19:03
See How to Ask. Please research.
– philipxy
Nov 4 at 19:04
See How to Ask. Please research.
– philipxy
Nov 4 at 19:04
add a comment |
1 Answer
1
active
oldest
votes
up vote
4
down vote
accepted
There is a logical order to evaluation of the query text, but the database engine can choose what order execute the query components based upon what is most optimal. The logical text parsing ordering is listed below. That is, for example, why you can't use an alias from SELECT clause in a WHERE clause. As far as the query parsing process is concerned, the alias doesn't exist yet.
FROM
ON
OUTER
WHERE
GROUP BY
CUBE | ROLLUP (these are not present in MySQL but are in some other SQL dialects)
HAVING
SELECT
DISTINCT
ORDER BY
LIMIT (or, in MSSQL, TOP)
See the Microsoft documentation (see "Logical Processing Order of the SELECT statement") for more information on this.
nice answer ... it would be better with a reference
– Dan Farrell
Nov 4 at 17:48
1
@DanFarrell : done.
– rsjaffe
Nov 4 at 17:50
1
Question is tagged MySQL. There is noTOPin MySQL; instead the keword isLIMIT
– Madhur Bhaiya
Nov 4 at 18:12
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
4
down vote
accepted
There is a logical order to evaluation of the query text, but the database engine can choose what order execute the query components based upon what is most optimal. The logical text parsing ordering is listed below. That is, for example, why you can't use an alias from SELECT clause in a WHERE clause. As far as the query parsing process is concerned, the alias doesn't exist yet.
FROM
ON
OUTER
WHERE
GROUP BY
CUBE | ROLLUP (these are not present in MySQL but are in some other SQL dialects)
HAVING
SELECT
DISTINCT
ORDER BY
LIMIT (or, in MSSQL, TOP)
See the Microsoft documentation (see "Logical Processing Order of the SELECT statement") for more information on this.
nice answer ... it would be better with a reference
– Dan Farrell
Nov 4 at 17:48
1
@DanFarrell : done.
– rsjaffe
Nov 4 at 17:50
1
Question is tagged MySQL. There is noTOPin MySQL; instead the keword isLIMIT
– Madhur Bhaiya
Nov 4 at 18:12
add a comment |
up vote
4
down vote
accepted
There is a logical order to evaluation of the query text, but the database engine can choose what order execute the query components based upon what is most optimal. The logical text parsing ordering is listed below. That is, for example, why you can't use an alias from SELECT clause in a WHERE clause. As far as the query parsing process is concerned, the alias doesn't exist yet.
FROM
ON
OUTER
WHERE
GROUP BY
CUBE | ROLLUP (these are not present in MySQL but are in some other SQL dialects)
HAVING
SELECT
DISTINCT
ORDER BY
LIMIT (or, in MSSQL, TOP)
See the Microsoft documentation (see "Logical Processing Order of the SELECT statement") for more information on this.
nice answer ... it would be better with a reference
– Dan Farrell
Nov 4 at 17:48
1
@DanFarrell : done.
– rsjaffe
Nov 4 at 17:50
1
Question is tagged MySQL. There is noTOPin MySQL; instead the keword isLIMIT
– Madhur Bhaiya
Nov 4 at 18:12
add a comment |
up vote
4
down vote
accepted
up vote
4
down vote
accepted
There is a logical order to evaluation of the query text, but the database engine can choose what order execute the query components based upon what is most optimal. The logical text parsing ordering is listed below. That is, for example, why you can't use an alias from SELECT clause in a WHERE clause. As far as the query parsing process is concerned, the alias doesn't exist yet.
FROM
ON
OUTER
WHERE
GROUP BY
CUBE | ROLLUP (these are not present in MySQL but are in some other SQL dialects)
HAVING
SELECT
DISTINCT
ORDER BY
LIMIT (or, in MSSQL, TOP)
See the Microsoft documentation (see "Logical Processing Order of the SELECT statement") for more information on this.
There is a logical order to evaluation of the query text, but the database engine can choose what order execute the query components based upon what is most optimal. The logical text parsing ordering is listed below. That is, for example, why you can't use an alias from SELECT clause in a WHERE clause. As far as the query parsing process is concerned, the alias doesn't exist yet.
FROM
ON
OUTER
WHERE
GROUP BY
CUBE | ROLLUP (these are not present in MySQL but are in some other SQL dialects)
HAVING
SELECT
DISTINCT
ORDER BY
LIMIT (or, in MSSQL, TOP)
See the Microsoft documentation (see "Logical Processing Order of the SELECT statement") for more information on this.
edited Nov 5 at 3:53
answered Nov 4 at 17:46
rsjaffe
3,36871431
3,36871431
nice answer ... it would be better with a reference
– Dan Farrell
Nov 4 at 17:48
1
@DanFarrell : done.
– rsjaffe
Nov 4 at 17:50
1
Question is tagged MySQL. There is noTOPin MySQL; instead the keword isLIMIT
– Madhur Bhaiya
Nov 4 at 18:12
add a comment |
nice answer ... it would be better with a reference
– Dan Farrell
Nov 4 at 17:48
1
@DanFarrell : done.
– rsjaffe
Nov 4 at 17:50
1
Question is tagged MySQL. There is noTOPin MySQL; instead the keword isLIMIT
– Madhur Bhaiya
Nov 4 at 18:12
nice answer ... it would be better with a reference
– Dan Farrell
Nov 4 at 17:48
nice answer ... it would be better with a reference
– Dan Farrell
Nov 4 at 17:48
1
1
@DanFarrell : done.
– rsjaffe
Nov 4 at 17:50
@DanFarrell : done.
– rsjaffe
Nov 4 at 17:50
1
1
Question is tagged MySQL. There is no
TOP in MySQL; instead the keword is LIMIT– Madhur Bhaiya
Nov 4 at 18:12
Question is tagged MySQL. There is no
TOP in MySQL; instead the keword is LIMIT– Madhur Bhaiya
Nov 4 at 18:12
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53143613%2fis-there-any-specific-order-of-execution-in-sql-query%23new-answer', 'question_page');
}
);
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
5
periscopedata.com/blog/sql-query-order-of-operations
– scaisEdge
Nov 4 at 17:45
1
The whole point of languages like SQL is for you to describe (logically) what you want, and to leave it up to the optimizer about how best to produce that result. That's why e.g. execution order is far more loosely defined with SQL than with many procedural languages.
– Damien_The_Unbeliever
Nov 4 at 18:32
Possible duplicate of What's the execute order of the different parts of a SQL select statement?
– philipxy
Nov 4 at 19:03
See How to Ask. Please research.
– philipxy
Nov 4 at 19:04