Reputation: 11
I am facing an issue while trying to merge the resultset of two sql queries for the same table.There is a call status column for the calls table.I want to have a resultset where I want to get 20 calls with status Completed and all calls with planned status for a contact from the same table called as Calls.Then order by the entire resultset by date and start time of call.I am trying to do something like this :
(SELECT * ' +
'FROM calls ' +
'WHERE primary_contact=' + id + ' ' +
'AND callstatus="Planned")' ;
'UNION (SELECT * ' +
'FROM calls ' +
'WHERE primary_contact=' + id + ' ' +
'AND callstatus="Completed"' +
'LIMIT 0,20)' +
'ORDER BY calldate || " " || stime DESC ';
This query is not working for me.Can anyone please help me and let me know where Iam I going wrong?
Thanks in advance !!
Upvotes: 0
Views: 102
Reputation: 6057
Try with this:
SELECT *
FROM calls
WHERE primary_contact = :id AND
callstatus = 'Planned'
UNION
SELECT *
FROM (
SELECT *
FROM calls
WHERE primary_contact = :id AND
callstatus = 'Completed'
LIMIT 20
)
ORDER BY calldate, stime;
Upvotes: 1