0

How can I select from two tables where table 1 returns 1 row and table 2 returns multiple rows resulting in NO duplicates from table 1?

Below, page.title has one row.  page_images.image_loc can have anything from 1 to 10. If page_images.image_loc has 2 or more, page.title will be duplicated for the count of page_images.image_loc rows. How can I limit page.title to 1, but not page_images.image_loc?

$query = mysql_query("
                      SELECT page.title,
                      page_images.image_loc
                      FROM page, page_images
                      WHERE page.url_category = '$category' AND
                      page.url_title = page_images.page_title
                    ");

1 Answer 1

1

You could try SELECT page.title, GROUP_CONCAT(page_images.image_loc) AS image_locs ... GROUP BY page.title to collect all the image_loc values in one row, then separate the list with explode().

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.