Timeline for Find the column given a data-value in SQL
Current License: CC BY-SA 4.0
Post Revisions
13 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Apr 27 at 20:50 | history | edited | Dale K | CC BY-SA 4.0 |
deleted 8 characters in body
|
| Apr 27 at 20:22 | comment | added | kesarling | @Charlieface I did not create the db. This is a production Db and the running joke is, it was created in the Stone Age. | |
| Apr 27 at 19:36 | answer | added | Lukasz Szozda | timeline score: 4 | |
| Apr 27 at 18:41 | answer | added | Charlieface | timeline score: 1 | |
| Apr 27 at 18:38 | comment | added | Charlieface |
I guess the real question would be why do you have 68 columns in the first place. Perhaps your table should be redesigned unpivoted to begin with. That would get you out of having to write so many ORs though, even if you have to write the actual names.
|
|
| Apr 27 at 18:16 | vote | accept | kesarling | ||
| Apr 27 at 18:04 | answer | added | DanOrc | timeline score: 2 | |
| Apr 27 at 17:57 | comment | added | kesarling | @MatBailie Snowflake. PS: That still wouldn't get me out of having to write 68 column names (which are not short... because why would they be?... sigh). | |
| Apr 27 at 17:52 | comment | added | MatBailie |
It depends on the dialect of SQL. PostgreSQL, for example would support WHERE 'val' IN (col1, col2, ..., coln) So, which, RDBMS are you using?
|
|
| Apr 27 at 17:43 | history | edited | kesarling | CC BY-SA 4.0 |
added a PS
|
| Apr 27 at 17:41 | comment | added | kesarling | That being said, these columns technically do not repeat. It is just that I do not exactly know what column holds the data value because someone had the bright idea of not enforcing template rules on the data when they represent nothing similar to each other. | |
| Apr 27 at 17:38 | comment | added | Pércoles Tiago Napivoski | I think you should normalise your database. Repeating columns should not be done that way. Take a look at First Normal Form. | |
| Apr 27 at 17:31 | history | asked | kesarling | CC BY-SA 4.0 |