You are probably looking for unions if you want to join result of multiple queries or if you want to achieve just your solution the go ahead with above answer(order needs to be taken care of though):
select id,name from phonebook WHERE (name='') AND (Tag ='') AND Country= '' UNION
select id,name from phonebook WHERE (name='') AND Country= '' UNION
select id,name from phonebook WHERE (tag='') AND Country= '';
As suggested by MatBailie in comment if you want duplication resulted in each query to remain than use UNION ALL
instead of UNION
.
MatBailie : UNION
will search through the results and remove duplicates. UNION ALL
won't even make that attempt. In this case we know in advance the three queries don't have the same results, so UNION ALL
will remove some redundant CPU effort. Also, UNION
can cause the ordering to change (do to the de-duplication), where as UNION ALL
doesn't (on the RDBMSes that I'm used to).
For your ordering here are two flavors
SELECT * FROM
(
select id,name from phonebook WHERE (name='') AND (Tag ='') AND Country= '' order by Points
) DUMMY_ALIAS1
UNION ALL
SELECT * FROM
(
select id,name from phonebook WHERE (name='') AND Country= '' order by Points
) DUMMY_ALIAS2
UNION ALL
SELECT * FROM
(
select id,name from phonebook WHERE (tag='') AND Country= '' order by Points
) DUMMY_ALIAS3
OR
select id,name, points from phonebook WHERE (name='') AND (Tag ='') AND Country= '' UNION
select id,name, points from phonebook WHERE (name='') AND Country= '' UNION
select id,name, points from phonebook WHERE (tag='') AND Country= '' order by Points;