Jump to content

Combine Two Selects...


drbigfresh

Recommended Posts

I am doing a select twice, each time checking for a different flag. I am wondering if there is anyway to combine the two selects so I am only making one trip to the database. The selects looks like this:

 

Select 1:

select wedding_guest.fname, wedding_guest.mi, wedding_guest.lname, wedding_prefix.prefix, wedding_guest.type from wedding_guest left outer join wedding_prefix on wedding_guest.prefix = wedding_prefix.id where ( wedding_guest.InviteID = 1 ) and ( weddingid = '1) and ( type = 'P' )

 

Select 2:

select wedding_guest.fname, wedding_guest.mi, wedding_guest.lname, wedding_prefix.prefix, wedding_guest.type from wedding_guest left outer join wedding_prefix on wedding_guest.prefix = wedding_prefix.id where ( wedding_guest.InviteID = 1 ) and ( weddingid = '1) and ( type = 'S' )

 

The only difference is the type flag, in one I am looking for the 'P' value and the other the 'S' value. Is it possible to combine these two?

 

Thanks!

Link to comment
Share on other sites

Okay...maybe I'm making this too simple, but are you simply wanting to pull all records with with inviteID = 1, weddingid = 1, and all records with a type of P or S?

 

If so...

 

select wedding_guest.fname, wedding_guest.mi, wedding_guest.lname, wedding_prefix.prefix, wedding_guest.type from wedding_guest left outer join wedding_prefix on wedding_guest.prefix = wedding_prefix.id where ( wedding_guest.InviteID = 1 ) and ( weddingid = '1) and (type = 'P' OR type = 'S' );

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

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

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  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...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.