How can I rewrite a multi-column IN clause to work on SQLite?

前端 未结 3 1477
后悔当初
后悔当初 2020-12-09 04:02

I\'ve got a query that looks something like this:

SELECT
  *
FROM table
WHERE
  (col1, col2) in (
    (\'col1_val1\', \'col2_val1\'),
    (\'col1_val2\', \'c         


        
3条回答
  •  遥遥无期
    2020-12-09 04:47

    Here's an easy solution that works, but it might not perform well on large data sets because it can't use any of your indexes.

    SELECT * FROM table
    WHERE col1 || '-' || col2 in (
      'col1_val1-col2_val1',
      'col1_val2-col2_val2',
      'col1_val3-col2_val3'
    )
    

    Try it in sqlfiddle

    Enjoy!

提交回复
热议问题