0

I have the following query:

(SELECT entry_type AS action, count(entries.type_id) as total
FROM entries
LEFT JOIN type ON entries.type_id = type.type_id
GROUP BY entry_type) 
UNION
(SELECT outcome AS action, count(entries.out_id) as total
FROM entries
LEFT JOIN outcomes ON entries.out_id = outcomes.out_id
GROUP BY outcome);

I had to make this union cause I need both entry_type and outcome counts to be on the following chart.

amChart

From Call to Follow Up Contact I get from the 'entry_type' and the rest from outcomes.

Thing is, I need to sort this so New Appointment Booked ( an outcome ) show right after Walk In, No interest after that and you got the idea...

I tried the following (and some other stuff before that) for testing purposes...

SELECT * FROM ( 
(SELECT entry_type AS action, count(entries.type_id) as total
FROM entries
LEFT JOIN type ON entries.type_id = type.type_id
GROUP BY entry_type) UNION
(SELECT outcome AS action, count(entries.out_id) as total 
FROM entries
LEFT JOIN outcomes ON entries.out_id = outcomes.out_id
GROUP BY outcome)) AS u
ORDER BY FIELD(type_id, 2,1);

No success.

Any ideas on how to approach this?

Lberteh
  • 165
  • 13
  • you can have custom `order by` . You can have individual blocks of a union create a made-up last column with its segment number and order by that. Just use what you need. – Drew Jul 12 '16 at 19:43
  • see http://stackoverflow.com/q/9378613 – Drew Jul 12 '16 at 19:43
  • Hi, Drew. Not sure what you mean by that. How can I create a made-up last column shared by both select statements? – Lberteh Jul 13 '16 at 14:52
  • 1
    I will invite you to the [Campaigns](http://chat.stackoverflow.com/rooms/95290) room or just come there by a click. – Drew Jul 13 '16 at 15:01

0 Answers0