Welcome Guest, Not a member yet? Register   Sign In
get from 2 tables which are connected
#6

[eluser]vitoco[/eluser]
This is the query, but analize it, and read documentation to learn well.

Code:
SELECT
  a.id AS article_id ,
  a.name AS article_name ,
  COUNT( c.id ) AS num_categories ,
  GROUP_CONCAT( c.name ) AS categorie_names
FROM
  article AS a
LEFT JOIN
  article_cats AS ac
ON
  ( a.id = ac.article_id )
LEFT JOIN
  cats AS c
ON
  ( ac.cat_id = c.id )
GROUP BY
  a.id

if you need to add conditions, use WHERE and/or HAVING depending on the field

Saludos


Messages In This Thread
get from 2 tables which are connected - by El Forum - 08-24-2012, 10:00 AM
get from 2 tables which are connected - by El Forum - 08-24-2012, 10:16 AM
get from 2 tables which are connected - by El Forum - 08-24-2012, 10:52 AM
get from 2 tables which are connected - by El Forum - 08-24-2012, 10:53 AM
get from 2 tables which are connected - by El Forum - 08-24-2012, 11:44 AM
get from 2 tables which are connected - by El Forum - 08-24-2012, 12:58 PM
get from 2 tables which are connected - by El Forum - 08-24-2012, 02:39 PM
get from 2 tables which are connected - by El Forum - 08-24-2012, 04:26 PM
get from 2 tables which are connected - by El Forum - 08-25-2012, 11:08 AM
get from 2 tables which are connected - by El Forum - 08-25-2012, 02:57 PM
get from 2 tables which are connected - by El Forum - 08-25-2012, 04:25 PM



Theme © iAndrew 2016 - Forum software by © MyBB