我得到了兩張幾乎相同的表格,這兩張表格之間的某些行的順序是混合在一起的。我會給你一個例子,說明我的表看起來像:如何比較兩個表並選擇順序中的差異?
table 1
:
colum1 | colum2 | colum3
-------+--------+-----------
test1 | pizza | margarita
test1 | pizza | cheese
test1 | pizza | hawaii
test1 | burger | salad
test2 | pizza | margarita
test2 | pizza | ham
test2 | burger | tomat
test2 | burger | salad
test3 | pig | green
test3 | cow | green
test3 | cow | yellow
test3 | pig | bird
table 2
:
colum1 | colum2 | colum3
-------+--------+------------
test1 | pizza | margarita
test1 | pizza | hawaii <-- different spot than before
test1 | pizza | cheese <-- different spot than before
test1 | burger | salad
test2 | pizza | margarita
test2 | pizza | ham
------ | ------ | --------- <-- no value between those (so its missing)
test2 | burger | salad
test3 | pig | green
test3 | cow | green
test3 | cow | yellow
test3 | pig | bird
所以你可以在上面的表格中看到,有一排混合並且有一個缺失的行。現在我想進行如下查詢:「如果colum1相同,則檢查行是否與其他表的順序相同」如果不是這樣「將所有行顯示爲長如colum1具有相同的值「那麼,結果將是這樣的:
table1 table2
------+-------+-----------+-------+-------+-----------
test1 | pizza | margarita | test1 | pizza | margarita
test1 | pizza | cheese | test1 | pizza | hawaii <<<shows all `test1` because this one is different
test1 | pizza | hawaii | test1 | pizza | cheese
test1 | burger| salad | test1 | pizza | salad
test2 | pizza | margarita | test2 | pizza | margarita
test2 | pizza | ham | test2 | pizza | ham
test2 | burger| tomat | | | <<<shows all `test2` because this one is different
test2 | burger| salad | test2 | burger| salad
另外:一行(這樣colum1,colum2,colum3組合的)始終相同。
那麼,這是SQL的某種可能嗎?或者我應該使用其他方法來做到這一點?
這是什麼意思*訂單*在這裏? –
表格數據是無序的。 – jarlh
這是一個簡單的有序完整外部聯接,其中過濾掉第二個表格列中的一個空值。獎金:這是沒有意義的「如果一列相同,然後檢查所有列是相同的,簡單去」所有列都是一樣的 –