SQL Query

4 posts by 2 authors in: Forums > CMS Builder
Last Post: July 30, 2013   (RSS)

By Toledoh - July 26, 2013

Hi Guys,

How do I do a "OR" search? ie

SELECT s.num FROM `<?php echo $TABLE_PREFIX . nlb_subscriber_table() ?>` s
 WHERE s.`<?php echo nlb_subscriber_confirmedField() ?>` = 1
   AND (`membership_type` = '5')

OR (`membership_type` = '3')

Thanks!

Cheers,

Tim (toledoh.com.au)

By gregThomas - July 29, 2013

Hi Tim,

In this case you might be better using an IN statement, something like this should work:

SELECT s.num FROM `<?php echo $TABLE_PREFIX . nlb_subscriber_table() ?>` s
 WHERE s.`<?php echo nlb_subscriber_confirmedField() ?>` = 1
   AND `membership_type` IN('5','3')

So the IN function checks if a field contains the comma separated values in the function.

Cheers

Greg

Greg Thomas







PHP Programmer - interactivetools.com

By Toledoh - July 29, 2013

Perfect. Thanks.

Is there any resources where I can read up on this kind of thing?  Or even better, a list of common queries that would be used with CMSB?

Cheers,

Tim (toledoh.com.au)