开发者

Search a query in multiple MySQL tables

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 wro开发者_高级运维ng to use UNION >?!


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?


UNION is fine there.


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


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%'
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜