select - Questions about SQL query -


i need select exam results of students in class 7a, need table (student_profile) identify students in 7a (identify student_id). wonder of following method faster, assume index student_id created in both tables:

method 1:

select * exam_results r exists  (select 1    student_profile p   p.student_id = r.student_id     , p.class = '7a') 

method 2:

select * exam_results student_id in  (select student_id   student_profile   class = '7a') 

thanks in advance,

jonathan

short answer, doesn't matter. query engine treat them same.

personally, i'd consider syntax.

select             r.*                 exam_results r         join             student_profile p                 on p.student_id = r.student_id                p.class = '7a' 

the inner implicit if omitted.

you'll same performance because modern query engines developed but, think standard syntax more extendable , easier read.


if extend query in future, multiple join conditons easier optimize multiple exists or ins.


Comments

Popular posts from this blog

.htaccess - First slash is removed after domain when entering a webpage in the browser -

Automatically create pages in phpfox -

c# - Farseer ContactListener is not working -