tags:

views:

45

answers:

4

hey guys i just want to search ( Select ) in multiple tables , so i wrote bellow code :

SELECT s.title From table_stories s WHERE s.title = %$inputbox% 
    UNION
    SELECT e.title From table_pages e WHERE e.title = %$inputbox%

is it wrong to use UNION >?!

+2  A: 

In the case of what you're doing here, it's perfectly reasonable to use UNION. Is there any particular reason why you think it might be wrong?

Mark Baker
A: 

UNION is fine there.

Zaki
A: 

That seems perfectly valid. As you are asking I assume it doesn't work as expected. Are you trying to do something else? If you want to order the result then enclose the queries in parantheses

(SELECT s.title AS t From table_stories s WHERE s.title = %$inputbox%)
UNION
(SELECT e.title AS t From table_pages e WHERE e.title = %$inputbox%)
ORDER BY t
John P
A: 

problem was not in using UNION , just mistake in Where condition

SELECT s.title AS t From table_stories s WHERE s.title like '%$inputbox%'
Mac Taylor