streamlining a MySQL query

octane

I have issues, OK!
Before you all laugh at this, it's worth noting this code is about a year and half old [when I first started out].

I've just come back to it all, and I need to streamline the code, so I came here to get some feedback.

This is a sample of the code:

AND (
user.section1 = 'search_string' AND data.section1 = 'Y'
OR
user.section2 = 'search_string' AND data.section2 = 'Y'
OR
user.section3 = 'search_string' AND data.section3 = 'Y'
OR
user.section4 = 'search_string' AND data.section4 = 'Y'
OR
user.section5 = 'search_string' AND data.section5 = 'Y'
OR
user.section6 = 'search_string' AND data.section6 = 'Y'
OR
user.section7 = 'search_string' AND data.section7 = 'Y'
OR
user.section8 = 'search_string' AND data.section8 = 'Y'
OR
user.section9 = 'search_string' AND data.section9 = 'Y'
OR
user.section10 = 'search_string' AND data.section10 = 'Y'
)

What I'd like to do is say:

Look for this string: 'search_string' in the user.sections from 1 to 10 where the value: 'y' appears in data.sections from 1 to 10.

The above works, but it's just getting on my nerves, now...
 
Back
Top