Froggaard Posted November 14, 2013 Share Posted November 14, 2013 Hello.I have this code $get_cart_info = mysql_query("select c.*,g.*,m.* from cart as c left join games as g on c.tid = g.id left join movies as m on c.tid=m.id where c.user = {$CURUSER['id']} GROUP BY c.tid") or die(mysql_error()); But what I need is when c.type is movie its only takes info from movies tabel, but still have to take everything out, because I both have movies and games in cart..Can it be done, or do I have to trying something else? Link to comment Share on other sites More sharing options...
justsomeguy Posted November 14, 2013 Share Posted November 14, 2013 It sounds like you need a union. Do one query where the type is movie where you join on the movies table, and do a union with another query where the type is not movie and you join on the games table. The only trick is that both queries in the union need to return the same list of columns, so you may need to either use some column aliases or empty values for columns that you need from one table but not another. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now