GMgKe586q6suSQnyqZLlGCooeWM

Pages

Search

Thursday, February 24, 2011

SQL - Complicated Queries

The table structure is like this below:
1. teacher table:
   a. id
   b. name
2. subject table:
  a. id
  b. major
3. handler table: who teacher handle the major
  a. id
  b. tid   // teacher id
  c. sid   // subject id

The problem is how to get a display of the third table with naming by using just one select statement. The answer is below:
SELECT t.name, s.major FROM teacher t, subject s, handler
WHERE handler.tid = t.id AND handler.sid = s.id
Share/Bookmark

No comments:

Post a Comment