如何針對以下情況執行SQL查詢?假設您有兩個表:table1和table2,其中table1中的每個條目可以在table2中有多個相應的條目。爲此,我想查詢的僞代碼爲:SQL查詢加入問題
for each $row in table1
$rows = find all rows in table2 that corresponds to $row with $row.id == table2.foreign_id
# $rows is an array of corresponding row in table2
if all rows in $rows meet some condition
then
return $row
else
continue
end
end
編輯:音符在上面的僞代碼,我只希望有它的所有關係,在符合某些條件下,不只是一些條件TABLE2在表1的行在table1中。
PS:我想在SQL中這樣做,因爲效率問題,否則我可能會遇到問題。
非常感謝。
非常感謝您的信息。這個網站仍然是新的。 :) – fzhou 2010-06-25 18:28:13