Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 29th, 2012  |  syntax: None  |  size: 0.71 KB  |  hits: 22  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. query stops working when trying to group_concat says unknown column
  2. SELECT
  3.     table1.items,
  4.     table2.opt1,
  5.     table3.opt2
  6.  
  7. FROM table1
  8.  
  9. LEFT JOIN table2 ON table1.id = table2.table1_id
  10. ...
  11. LEFT JOIN table3 ON table2.id = table3.table2_id
  12. WHERE
  13. ...
  14. GROUP BY table1.items
  15. HAVING
  16. (SELECT COUNT(*) FROM table3 WHERE table3.table2_id = table2.id AND (table3.opt2 = 1)) = (1)
  17.        
  18. SELECT
  19.    table1.items,
  20.    table2.opt1,
  21.    GROUP_CONCAT(table3.opt2 SEPERATOR ', ') as concat_opt2
  22.  
  23. FROM table1
  24.  
  25. LEFT JOIN table2 ON table1.id = table2.table1_id
  26. ...
  27. LEFT JOIN table3 ON table2.id = table3.table2_id
  28. WHERE
  29. ...
  30. GROUP BY table1.items
  31. HAVING
  32. (SELECT COUNT(*) FROM table3 WHERE table3.table2_id = table2.id  AND (table3.opt2 = 1)) = (1)