Loading

customer notes with tags

  1. SELECT tbl1.*,
  2. (SELECT GROUP_CONCAT(access_name SEPARATOR ',')
  3. FROM access_staff af, access a, access_notes an
  4. WHERE af.staff_id = 236
  5. AND a.access_id = af.access_id
  6. AND a.access_id = an.access_id
  7. AND an.note_id = tbl1.id_customer_note) tag
  8. FROM (
  9. SELECT DISTINCT customer_notes.id_customer_note, customer_notes.`date`, staff.sname, trading_name.id_trading_name, trading_name.trading_name,
  10. contact.cname, customer_notes.note
  11. FROM customer_notes
  12. INNER JOIN access_notes ON access_notes.note_id = customer_notes.id_customer_note
  13. INNER JOIN access ON access_notes.access_id = access.access_id
  14. INNER JOIN access_staff ON access_staff.access_id = access.access_id
  15. INNER JOIN staff ON customer_notes.staff_id = staff.id_staff
  16. INNER JOIN contact ON customer_notes.customer_id = contact.id_contact
  17. INNER JOIN trading_name ON contact.trading_id = trading_name.id_trading_name
  18. WHERE (access_staff.staff_id = 236) AND (customer_notes.deleted = 0)
  19. ORDER BY customer_notes.id_customer_note DESC
  20. LIMIT 20) tbl1;

Comments