Search multiple columns in sqlite SELECT FROM

前端 未结 4 1687
鱼传尺愫
鱼传尺愫 2021-01-29 12:04

I use this code to search for Column A. What modification should I make if I want to search Column A and Column B simultaneously?

String sql = \"SELECT * FROM \"         


        
相关标签:
4条回答
  • 2021-01-29 12:18

    This solved my problem:

    String sql = "SELECT * FROM " + TABLE_NAME +
                    " WHERE " + ColumnA + " OR " + ColumnB + " LIKE ? ORDER BY " + ColumnA + " LIMIT 100";
    

    I should use one select statement.

    0 讨论(0)
  • 2021-01-29 12:34

    Are you looking for UNION instead of OR? http://www.tutorialspoint.com/sqlite/sqlite_unions_clause.htm

    0 讨论(0)
  • 2021-01-29 12:35

    You can use OR to connect two expressions. However, both must be complete expressions:

    SELECT ... WHERE ColA LIKE ? OR ColB LIKE ? ...
    
    0 讨论(0)
  • 2021-01-29 12:35

    Make two differrent query. And combine results by union keyword.

    select * from TABLE_NAME where columnA like ? order by columnA limit 100
    union
    select * from TABLE_NAME where columnB like ? order by columnA limit 100
    
    0 讨论(0)
提交回复
热议问题