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?

Link to comment
Share on other sites

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???

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.