SELECT * FROM SUSE_DEV.PROJECT_LISTING INNER JOIN SUSE_DEV.PROJECT_AUCTION ON SUSE_DEV.PROJECT_LISTING.PROJECT_CODE on ( SELECT * FROM SUSE_DEV.PROJECT_AUCTION WHERE SUSE_DEV.PROJECT_AUCTION.GMT_START > SYSDATE )
这段SQL里的子查询是肯定会返回多条的。一般来说,用ON是根本不能解决这样的问题,有些人说,可以用
and rownum = 1
SELECT * FROM SUSE_DEV.PROJECT_LISTING INNER JOIN SUSE_DEV.PROJECT_AUCTION ON SUSE_DEV.PROJECT_LISTING.PROJECT_CODE on ( SELECT * FROM SUSE_DEV.PROJECT_AUCTION WHERE SUSE_DEV.PROJECT_AUCTION.GMT_START > SYSDATE and rownum = 1 )
这样只能处理返回的值的的确确只有一条的情况,那如果我要返回的有多条呢?答案就是用in
SELECT * FROM SUSE_DEV.PROJECT_LISTING INNER JOIN SUSE_DEV.PROJECT_AUCTION ON SUSE_DEV.PROJECT_LISTING.PROJECT_CODE IN ( SELECT * FROM SUSE_DEV.PROJECT_AUCTI IN WHERE SUSE_DEV.PROJECT_AUCTION.GMT_START > SYSDATE )
这样就可以了。有人说用exists也可以,我没有试过。有兴趣大家可以试试。
时间: 2024-09-26 10:35:42