select statement over multiple columns in SQLite

22,831

If I understand right, you just need to use Or keyword and search thru all the kw-fields

sqlite> select issue,url,steps from help where kw1='ie' or kw2='ie' or kw3='ie' or kw4='ie' or kw5='ie' or kw6='ie' or kw7='ie' or kw8='ie' or kw9='ie' or kw10='ie' or kw11='ie' or kw12='ie';
Share:
22,831
Justin Gould
Author by

Justin Gould

Updated on July 09, 2022

Comments

  • Justin Gould
    Justin Gould almost 2 years

    I have a db w/ table named help w/ columns named i_id,issue,url,steps,kw1,kw2...kw12.

    kw1-kw12 have one word in the field as keywords and can be null.

    when I do:

    sqlite> select issue,url,steps from help where kw1='adobe';
    

    I get:

    blank popup|blankpopup.html|S
    missing pdfs|missingpdfs.html|S
    printall not populating|printall.html|A
    

    this is right. My question is when I move to another keyword like 'ie' that is in multiple fields across kw1-kw12, how do I a select statement where instead of searching just kw1, it searches kw1 through kw12?

    I know what fields ie is in. I have an excel sheet that tells me how the db is built but the people using the db will not have access to it.

  • Justin Gould
    Justin Gould almost 12 years
    that worked great! I didn't ever think about or. I was trying with 'and'. I guess my mind was dismissing the idea where I thought 'or would only give the response to the first correct field and stop. thank you.