chantown Posted November 30, 2007 Share Posted November 30, 2007 Hi, let's say I have 3 queries right now: "SELECT * FROM table WHERE action=1 AND scope=4"; "SELECT * FROM table WHERE type=4 AND action=2 AND scope=4"; "SELECT * FROM table WHERE type=6 AND action=3"; For each one, I generate a multi dimensional array result[column_name], and output the results to a table on the page. Suppose I want to Combine all of these queries so I get ALL of those results, how can I do that? I tried doing this: "SELECT * FROM table WHERE "; "(action=1 AND scope=4) "; "OR "; "type=4 AND action=2 AND scope=4 "; "OR "; "type=6 AND action=3 "; "GROUP BY ..."; And in the end, it only returns me the results of "type=6 AND action=3". Is there any way I can get all of them? thanks- Quote Link to comment https://forums.phpfreaks.com/topic/79516-multiple-wheres-in-select/ Share on other sites More sharing options...
nuxy Posted November 30, 2007 Share Posted November 30, 2007 Try putting brackets over the other statements. SELECT * FROM table WHERE (action=1 AND scope=4) OR (type=4 AND action=2 AND scope=4) OR (type=6 AND action=3) GROUP BY ..."; Quote Link to comment https://forums.phpfreaks.com/topic/79516-multiple-wheres-in-select/#findComment-402723 Share on other sites More sharing options...
chantown Posted November 30, 2007 Author Share Posted November 30, 2007 oh yes, that's what i meant, I did that. i put brackets on other statements, but it only returns me the last statement :/ Quote Link to comment https://forums.phpfreaks.com/topic/79516-multiple-wheres-in-select/#findComment-402731 Share on other sites More sharing options...
asmith Posted November 30, 2007 Share Posted November 30, 2007 i guess you need union syntax. this is what you need : http://dev.mysql.com/doc/refman/5.0/en/union.html Quote Link to comment https://forums.phpfreaks.com/topic/79516-multiple-wheres-in-select/#findComment-402810 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.