GMgKe586q6suSQnyqZLlGCooeWM

Pages

Search

Showing posts with label SQL. Show all posts
Showing posts with label SQL. Show all posts

Saturday, April 9, 2011

SQL - A Little Complex

A little complex queries:
 $q = "SELECT forum_topic.id, forum_topic.title, forum_user.username, forum_topic.date, forum_topic.time, count(forum_reply.tid) as 'count' FROM forum_user, forum_topic, forum_reply WHERE forum_user.id=forum_topic.uid AND forum_topic.id=forum_reply.tid GROUP BY forum_reply.tid";
Share/Bookmark

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