I have a union query as follows:
(SELECT t.id, t.name, c.company AS owner, t.creation_date AS date, t.notes FROM tool t, client c WHERE t.id_customer = '15' AND t.trash_flag = '1') UNION (SELECT f.id, f.name, CONCAT(m.first_name, ' ', m.last_name) AS owner, f.date, f.notes FROM file f, meta m WHERE ((f.acl = 0) OR (f.acl = 1 AND '1' = TRUE) OR (f.acl = 2 AND f.id = '7')) AND f.id = '15' AND f.trash_flag = '1' AND m.user_id = f.id_user) ORDER BY 'name' 'ASC' LIMIT 0,20Everything works fine but I have two questions:
- How do I add a column to the entire result set that gives the row number
- Could I do this without using UNION e.g. an advanced join?
Thanks for your time MySQL gurus!