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 gregThomas - July 30, 2013

Hi Tim,

Unfortunately we don't have a resource for common MySQL functions. I'm not sure it would be possible as so many queries are completely unique, and they become complicated once you've gone outside of the basic where statement.

Cheers

Greg

Greg Thomas







PHP Programmer - interactivetools.com