SQL is made to function on Joins, I wouldn't say that they are "kind of "expensive" operation" RDMS databases are made to relate to other tables. if you had Primary and Foreign Keys set up and/or even indexes then it shouldn't be an "expensive operation".
edit
here is the best query for what you are trying to accomplish.
SELECT player.name, player.surname
FROM player INNER JOIN person ON player.id = person.id
WHERE player.id = person.id
AND player.name = person.name
AND player.surname = person.surname
This is the write way to write the code, it's clean and straight forward to what is going on. your code essentially is doing the exact same thing, but is bad coding practice from my point of view.
SQL Fiddle Statistics and running code
SQL Fiddle Statistics for your code
(it actually looks like the execution is the same.)
I need to Note that both this query and the query that you are using join the two tables on their id columns. this is an issue because there is 1 id that holds different values in either table. so those id columns mean two totally separate things and shouldn't be joined on in all reality.
example:
player table
| 2001 | John | Carlin |
AND
person table
| 2001 | Pirlon | Austin |
in this specific instance the where statement covers the id being different, in this one case. BUT YOU NEED TO BE AWARE THIS IS BAD DATA you should fix the database.
Sorry to say but the INTERSECT
query that has been suggested actually takes longer and has more operations attached to it then both your original code and the code I posted.
SQL is made to function on Joins, I wouldn't say that they are "kind of "expensive" operation" RDMS databases are made to relate to other tables. if you had Primary and Foreign Keys set up and/or even indexes then it shouldn't be an "expensive operation".
edit
here is the best query for what you are trying to accomplish.
SELECT player.name, player.surname
FROM player INNER JOIN person ON player.id = person.id
WHERE player.id = person.id
AND player.name = person.name
AND player.surname = person.surname
This is the write way to write the code, it's clean and straight forward to what is going on. your code essentially is doing the exact same thing, but is bad coding practice from my point of view.
SQL Fiddle Statistics and running code
SQL Fiddle Statistics for your code
(it actually looks like the execution is the same.)
I need to Note that both this query and the query that you are using join the two tables on their id columns. this is an issue because there is 1 id that holds different values in either table. so those id columns mean two totally separate things and shouldn't be joined on in all reality.
example:
player table
| 2001 | John | Carlin |
AND
person table
| 2001 | Pirlon | Austin |
in this specific instance the where statement covers the id being different, in this one case. BUT YOU NEED TO BE AWARE THIS IS BAD DATA you should fix the database.
Sorry to say but the INTERSECT
query that has been suggested actually takes longer and has more operations attached to it then both your original code and the code I posted.
SQL is made to function on Joins, I wouldn't say that they are "kind of "expensive" operation" RDMS databases are made to relate to other tables. if you had Primary and Foreign Keys set up and/or even indexes then it shouldn't be an "expensive operation".
edit
here is the best query for what you are trying to accomplish.
SELECT player.name, player.surname
FROM player INNER JOIN person ON player.id = person.id
WHERE player.id = person.id
AND player.name = person.name
AND player.surname = person.surname
This is the write way to write the code, it's clean and straight forward to what is going on. your code essentially is doing the exact same thing, but is bad coding practice from my point of view.
SQL Fiddle Statistics and running code
SQL Fiddle Statistics for your code
(it actually looks like the execution is the same.)
I need to Note that both this query and the query that you are using join the two tables on their id columns. this is an issue because there is 1 id that holds different values in either table. so those id columns mean two totally separate things and shouldn't be joined on in all reality.
example:
player table
| 2001 | John | Carlin |
AND
person table
| 2001 | Pirlon | Austin |
in this specific instance the where statement covers the id being different, in this one case. BUT YOU NEED TO BE AWARE THIS IS BAD DATA you should fix the database.
Sorry to say but the INTERSECT
query that has been suggested actually takes longer and has more operations attached to it then both your original code and the code I posted.
(削除) Depending on how unique the Data in both tables is, which I think they will be the same where they match, you could probably leave out all the AND
statements in your WHERE
statement and just go with something like this
SELECT * FROM player
WHERE player.id in (Select person.ID FROM person)
I don't know exactly how fast this would be, I will do a SQLFiddle sometime today and see how fast this is. (削除ここまで)
SQL is made to function on Joins, I wouldn't say that they are "kind of "expensive" operation" RDMS databases are made to relate to other tables. if you had Primary and Foreign Keys set up and/or even indexes then it shouldn't be an "expensive operation".
edit
here is the best query for what you are trying to accomplish.
SELECT player.name, player.surname
FROM player INNER JOIN person ON player.id = person.id
WHERE player.id = person.id
AND player.name = person.name
AND player.surname = person.surname
This is the write way to write the code, it's clean and straight forward to what is going on. your code essentially is doing the exact same thing, but is bad coding practice from my point of view.
SQL Fiddle Statistics and running code
SQL Fiddle Statistics for your code
(it actually looks like the execution is the same.)
I need to Note that both this query and the query that you are using join the two tables on their id columns. this is an issue because there is 1 id that holds different values in either table. so those id columns mean two totally separate things and shouldn't be joined on in all reality.
example:
player table
| 2001 | John | Carlin |
AND
person table
| 2001 | Pirlon | Austin |
in this specific instance the where statement covers the id being different, in this one case. BUT YOU NEED TO BE AWARE THIS IS BAD DATA you should fix the database.
Sorry to say but the INTERSECT
query that has been suggested actually takes longer and has more operations attached to it then both your original code and the code I posted.
(削除) Depending on how unique the Data in both tables is, which I think they will be the same where they match, you could probably leave out all the AND
statements in your WHERE
statement and just go with something like this
SELECT * FROM player
WHERE player.id in (Select person.ID FROM person)
I don't know exactly how fast this would be, I will do a SQLFiddle sometime today and see how fast this is. (削除ここまで)
SQL is made to function on Joins, I wouldn't say that they are "kind of "expensive" operation" RDMS databases are made to relate to other tables. if you had Primary and Foreign Keys set up and/or even indexes then it shouldn't be an "expensive operation".
edit
here is the best query for what you are trying to accomplish.
SELECT player.name, player.surname
FROM player INNER JOIN person ON player.id = person.id
WHERE player.id = person.id
AND player.name = person.name
AND player.surname = person.surname
This is the write way to write the code, it's clean and straight forward to what is going on. your code essentially is doing the exact same thing, but is bad coding practice from my point of view.
SQL Fiddle Statistics and running code
SQL Fiddle Statistics for your code
(it actually looks like the execution is the same.)
I need to Note that both this query and the query that you are using join the two tables on their id columns. this is an issue because there is 1 id that holds different values in either table. so those id columns mean two totally separate things and shouldn't be joined on in all reality.
example:
player table
| 2001 | John | Carlin |
AND
person table
| 2001 | Pirlon | Austin |
in this specific instance the where statement covers the id being different, in this one case. BUT YOU NEED TO BE AWARE THIS IS BAD DATA you should fix the database.
Sorry to say but the INTERSECT
query that has been suggested actually takes longer and has more operations attached to it then both your original code and the code I posted.
SQL is made to function on Joins, I wouldn't say that they are "kind of "expensive" operation" RDMS databases are made to relate to other tables. if you had Primary and Foreign Keys set up and/or even indexes then it shouldn't be an "expensive operation".
edit
here is the best query for what you are trying to accomplish.
SELECT player.name, player.surname
FROM player INNER JOIN person ON player.id = person.id
WHERE player.id = person.id
AND player.name = person.name
AND player.surname = person.surname
This is the write way to write the code, it's clean and straight forward to what is going on. your code essentially is doing the exact same thing, but is bad coding practice from my point of view.
SQL Fiddle Statistics and running code
SQL Fiddle Statistics for your code
(it actually looks like the execution is the same.)
I need to Note that both this query and the query that you are using join the two tables on their id columns. this is an issue because there is 1 id that holds different values in either table. so those id columns mean two totally separate things and shouldn't be joined on in all reality.
example:
player table
| 2001 | John | Carlin |
AND
person table
| 2001 | Pirlon | Austin |
in this specific instance the where statement covers the id being different, in this one case. BUT YOU NEED TO BE AWARE THIS IS BAD DATA you should fix the database.
Sorry to say but the INTERSECT
query that has been suggested actually takes longer and has more operations attached to it then both your original code and the code I posted.
Depending on how unique the Data in both tables(削除) Depending on how unique the Data in both tables is, which I think they will be the same where they match, you could probably leave out all the AND
statements in your WHERE
statement and just go with something like this
SELECT * FROM player
WHERE player.id in (Select person.ID FROM person)
I don't know exactly how fast this would be, I will do a SQLFiddle sometime today and see how fast this is. (削除ここまで)
SQL is made to function on Joins, which I thinkwouldn't say that they willare "kind of "expensive" operation" RDMS databases are made to relate to other tables. if you had Primary and Foreign Keys set up and/or even indexes then it shouldn't be an "expensive operation".
edit
here is the same where they match,best query for what you could probably leave out all the AND
statements in your WHERE
statement and just go with something like thisare trying to accomplish.
SELECT *player.name, player.surname FROM player INNER JOIN person ON player.id = person.id
WHERE player.id in= (Selectperson.id
AND player.name = person.IDname
FROM AND player.surname = person).surname
I don't know exactly how fast this would beThis is the write way to write the code, I will do a SQLFiddle sometime todayit's clean and see how fast thisstraight forward to what is going on. your code essentially is doing the exact same thing, but is bad coding practice from my point of view.
SQLSQL Fiddle Statistics and running code
SQL Fiddle Statistics for your code
(it actually looks like the execution is made to function on Joins,the same.)
I wouldn't sayneed to Note that they are "kind of "expensive" operation" RDMS databasesboth this query and the query that you are made to relate to otherusing join the two tables on their id columns. if you had Primary and Foreign Keys set up this is an issue because there is 1 id that holds different values in either table. so those id columns mean two totally separate things and/or even indexes then it shouldn't be an "expensive operation"joined on in all reality.
example:
player table
| 2001 | John | Carlin |
AND
person table
| 2001 | Pirlon | Austin |
in this specific instance the where statement covers the id being different, in this one case. BUT YOU NEED TO BE AWARE THIS IS BAD DATA you should fix the database.
Sorry to say but the INTERSECT
query that has been suggested actually takes longer and has more operations attached to it then both your original code and the code I posted.
Depending on how unique the Data in both tables is, which I think they will be the same where they match, you could probably leave out all the AND
statements in your WHERE
statement and just go with something like this
SELECT * FROM player
WHERE player.id in (Select person.ID FROM person)
I don't know exactly how fast this would be, I will do a SQLFiddle sometime today and see how fast this is.
SQL is made to function on Joins, I wouldn't say that they are "kind of "expensive" operation" RDMS databases are made to relate to other tables. if you had Primary and Foreign Keys set up and/or even indexes then it shouldn't be an "expensive operation".
(削除) Depending on how unique the Data in both tables is, which I think they will be the same where they match, you could probably leave out all the AND
statements in your WHERE
statement and just go with something like this
SELECT * FROM player
WHERE player.id in (Select person.ID FROM person)
I don't know exactly how fast this would be, I will do a SQLFiddle sometime today and see how fast this is. (削除ここまで)
SQL is made to function on Joins, I wouldn't say that they are "kind of "expensive" operation" RDMS databases are made to relate to other tables. if you had Primary and Foreign Keys set up and/or even indexes then it shouldn't be an "expensive operation".
edit
here is the best query for what you are trying to accomplish.
SELECT player.name, player.surname FROM player INNER JOIN person ON player.id = person.id
WHERE player.id = person.id
AND player.name = person.name
AND player.surname = person.surname
This is the write way to write the code, it's clean and straight forward to what is going on. your code essentially is doing the exact same thing, but is bad coding practice from my point of view.
SQL Fiddle Statistics and running code
SQL Fiddle Statistics for your code
(it actually looks like the execution is the same.)
I need to Note that both this query and the query that you are using join the two tables on their id columns. this is an issue because there is 1 id that holds different values in either table. so those id columns mean two totally separate things and shouldn't be joined on in all reality.
example:
player table
| 2001 | John | Carlin |
AND
person table
| 2001 | Pirlon | Austin |
in this specific instance the where statement covers the id being different, in this one case. BUT YOU NEED TO BE AWARE THIS IS BAD DATA you should fix the database.
Sorry to say but the INTERSECT
query that has been suggested actually takes longer and has more operations attached to it then both your original code and the code I posted.