Jump to content

Data from more than 2 tables after one to many table join???


GregL83

Recommended Posts

Hello,

 

I have a query that joins two tables:

 

$query = "SELECT s.id, s.name, s.slug, s.overall_comments, uc1.scene_id, uc1.comment, uc1.update_time FROM scenes s, user_comments uc1 JOIN(SELECT scene_id, MAX(update_time) AS time FROM user_comments GROUP BY scene_id) AS uc2 ON uc1.scene_id = uc2.scene_id AND uc1.update_time = uc2.time WHERE ".likeQuery($keywords)." AND uc1.scene_id = s.id"

 

likeQuery is a function that returns a LIKE string for searching the particular fields... this all works fine

 

I would like to add additional tables to the mix...  Any idea how to do this?

I tried this and it return zero results:

 

$query = "SELECT s.id, s.name, s.slug, ct.name, s.overall_comments, uc1.scene_id, uc1.comment, uc1.update_time FROM scenes s, cities ct, user_comments uc1 JOIN(SELECT scene_id, MAX(update_time) AS time FROM user_comments GROUP BY scene_id) AS uc2 ON uc1.scene_id = uc2.scene_id AND uc1.update_time = uc2.time WHERE ".likeQuery($keywords)." AND uc1.scene_id = s.id AND s.city_id = ct.city_id"

 

Even if I just add an additional table to the FROM sequence, mysql stops returning results... any ideas???

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.