![](/img/trans.png)
[英]How to query mysql to select rows with non unique combination of two columns
[英]mySql select query with combination condition of two columns
在我的示例MySql
表中,我有一個表Table1
和三列id
, column1
和column2
。 在這里, columnn1
和column2
具有記錄的組合,例如來自兩個表的foreign_key。 現在,我在循環中有以下查詢。
SELECT t.id FROM `Table1` t WHERE t.column1 = 'value' and t.column2 = 'value';
在這里,我將獲得許多行,其中包含column1和column2的組合。 有沒有辦法為多個column1和column2值組合獲取此值?
在各種AND
組合之間的括號中使用OR
。
請嘗試以下操作:
SELECT t.id FROM `Table1` t
WHERE (t.column1 = 'value' and t.column2 = 'value')
OR
(t.column1 = 'value2' and t.column2 = 'value2')
OR
(t.column1 = 'value3' and t.column2 = 'value3')
OR
(t.column1 = 'value4' and t.column2 = 'value4')
... 等等
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.