如何针对以下情况执行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