我有三个名为User,Review和Business的表。我想使用 user_id 和 business_id business_name ,审核内容和 review_id >
我可以单独做到这一点:
SELECT business_name FROM Business WHERE business_id = 'XXXXX'
SELECT review_id, content FROM Review WHERE business_id = 'XXXXX' AND user_id = 'XXXX'
问题是如何将结果组合在一起?我得到了实现
SELECT review_id, content, business_name FROM ...
用户表
user_id
username
password
email
date_created
last_login
dob
评论表
review_id
user_id
business_id
rating
content
post_date
业务表
business_id
business_name
country
city
email
date_created
答案 0 :(得分:0)
如果我理解正确,您可以通过执行此查询来实现此目的:
SELECT a.business_name, b.review_id, b.content
FROM Business a, Review b
WHERE a.business_id = "XXXX" AND a.business_id=b.business_id AND b.user_id ="XXXX" ;
您可以按步骤对此进行成像:
首先,您选择ID为#34; XXXX"的某个商家名称来自商业表
然后从评论表
您只过滤ID为" XXXX"
答案 1 :(得分:0)
您可以在使用user_id连接的三个表User和Review表上使用Inner join,使用Business_id使用Review and Business表。
然后根据需要提供user_id和business_id特定值。