Mysql select where t4.name=x 并且 t2 或 t3 有一个 t1.user !? :)
为了解释我的问题,让我们想象 4 个表。
users - (userid, user.data)
buy - (buyid, productid, userid, buy.conditions)
sell - (sellid, productid, userid, sell.conditions)
产品 - (productid, Product.data)
我想做一个选择,当有用户购买或出售名称上带有 X 的产品时,返回所有用户和产品数据。
SELECT userid,
USER.DATA,
productid,
product.DATA
FROM users,
buy,
sell,
products
WHERE ( buy.userid = users.userid
OR sell.userid = users.userid )
AND ( buy.productid = product.productid
OR buy.productid = product.productid )
AND product.DATA LIKE '%x%'
这行不通,但我相信你明白我想要做什么。
To explain my problem lets imagine 4 tables.
users - (userid, user.data)
buy - (buyid, productid, userid, buy.conditions)
sell - (sellid, productid, userid, sell.conditions)
product - (productid, product.data)
I want to do a select that returns all the users and product data when there is a user that have products with X on the name to buy or sell.
SELECT userid,
USER.DATA,
productid,
product.DATA
FROM users,
buy,
sell,
products
WHERE ( buy.userid = users.userid
OR sell.userid = users.userid )
AND ( buy.productid = product.productid
OR buy.productid = product.productid )
AND product.DATA LIKE '%x%'
this doesnt work but I belive you get the idea of what I am tryng to do.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
尝试像下面这样的联合:
Try a union like below:
非常感谢大家!
在朋友的帮助下最终做了这样的事情:
Thanks a lot guys!
With the help from a friend end up making something like this:
您可以使用 EXISTS 子句:
You could use the EXISTS clause: