Jump to content

2 queries in one (mysql_)

Recommended Posts

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 post
Share on other sites

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 post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...