|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Hi,
I have a mysql database, usual setup with PHP+apache. In one table there are 16 columns, named "r1" through to "r16" (though name not important). I'd like to perform a query to select all records where any one of these 16 columns are set to a certain value. The mysql documentation describes how inefficient multiple ORs are, and it would be poor code to write "SELECT certain_things FROM table WHERE r1=$x OR r2=$x OR r3=$x ... OR r16=$x" Is there a nicer way of doing this? I'm sure that there must be. Thanks for any help! Henry |
|
#2
|
|||
|
|||
|
SQL works nicely with a normalized database, where repeated columns are avoided. Denormalized designs, like your table, can lead to some ungainly SQL. You could write it as WHERE '$x' IN (r1,r2,r3....r16) Last edited by obscurant : July 26th, 2002 at 01:37 PM. |
![]() |
| Viewing: Dev Articles Community Forums > Databases > MySQL Development > mysql multiple OR query |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|