2表查询正确协议

时间:2015-10-12 10:53:14

标签: php mysql

我有一个我需要修改的搜索结果查询,因此它不会显示已售出的产品。所以这是当前存在的非修改的select语句:

orderdetails table under

我需要对其进行修改,以便查看SELECT id, cid, **etc** FROM posts WHERE posts.id NOT IN orderdetails.DetailProductID DetailProductID`以查看它是否存在以及现在是否显示它;所以在本质上用英语来说就是这样的:

{{1}}

2 个答案:

答案 0 :(得分:0)

@Configuration
@EnableAutoConfiguration
@ComponentScan(basePackages = {"controllers"})
public class AppServer {
    ...
}

答案 1 :(得分:0)

SELECT 
id, cid, sid, posttitle, postdetails, city, state, zipcode 
FROM posts 
where posts.id not in (select DetailProductID from orderdetails)
ORDER BY datepublished DESC

或使用聪明的左连接

SELECT 
posts.id, posts.cid, posts.sid, posts.posttitle, posts.postdetails, posts.city, posts.state, posts.zipcode 
FROM posts 
LEFT JOIN orderdetails ON orderdetails.DetailProductID = posts.id
where orderdetails.DetailProductID is null
ORDER BY posts.datepublished DESC