Announcement

Announcement Module
Collapse
No announcement yet.

For good performance Join values or direct values?

Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • For good performance Join values or direct values?

    hello,

    assume i have two tables

    Table 1 courses

    course_id,title

    Table 2 scores

    user_id,course_id,grade

    i have a variable course_id is 2

    i have two queries which one of them have good performance?

    Query 1
    select courses.title,scores.grade from courses,scores where courses.course_id='2' and scores.course_id='2'

    Query 2
    select courses.title,scores.grade from courses,scores where courses.course_id='2' and scores.course_id=courses.course_id

  • #2
    You should always use Query 2.

    There is no performance difference between them because the value is known in advance. But in query 2 you explicitly show whoever is reading the code that there is a relation between the two tables.

    But please see my post on your other question regarding the use of INNER JOIN syntax to further improve on writing your queries easily understandable and reduce risk for bugs.

    Comment

    Working...
    X