John Davidson John Davidson - 2 years ago 83
MySQL Question

MySQL JOIN with LIMIT 1 on joined table

I want to join two tables, but only get 1 record of table2 per record on table1

For example:

SELECT, c.title, AS product_id, p.title
FROM categories AS c
JOIN products AS p ON = p.category_id

This would get me all records in
, which is not what I want. I want 1 [the first] product per category (I have a
column in the products field).

How do I go about doing that?

Answer Source

I would try something like this:

      (SELECT, P.title 
       FROM products as P
       WHERE P.category_id =
       LIMIT 1)
FROM categories C
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download