sql - Finding a single value among multiple columns -


i have circumstance need determine if single value exists in 1 of 20 different columns given user record, not position-specific. so, each user has 1 or more applications responsible maintaining , when particular application entered, query in 20 columns in users' record application value. dont want this:

select * users u  u.app1 = 'appl1' or u.app2 = 'appl1' or u.app3 = 'appl1' or... u.app20 = 'appl1' 

is there way simplify clause

where u.app* = 'appl1' 

no, cannot simplify where clause way. can use in:

select * users u 'appl1' in (u.app1, u.app2, u.app3,  . . . u.app20) 

in general, such repeated columns example of bad database design. should have table has 1 row per user/app combinations (say userapps). such table, query simpler.


Comments

Popular posts from this blog

How to mention the localhost in android -

php - Calling a template part from a post -