drbigfresh Posted August 18, 2007 Share Posted August 18, 2007 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 https://forums.phpfreaks.com/topic/65588-combine-two-selects/ Share on other sites More sharing options...
js_280 Posted August 18, 2007 Share Posted August 18, 2007 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 https://forums.phpfreaks.com/topic/65588-combine-two-selects/#findComment-327608 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.