如何使用子查询对选定列使用 where 条件?
我有两栏:公司和产品。
我使用以下查询来获取与特定字符串匹配的产品...
select id,(select name from company where product.cid=company.id) as
company,name,selling_price,mrp from product where name like '$qry_string%'
但是当我需要列出特定公司的产品时我该怎么办?
我尝试了以下方法,但本质上
select id,(select name from company where product.cid=company.id) as
company,name,selling_price,mrp from product where company like '$qry_string%'
帮助我
I have two columns as company and product.
I use the following query to get the products matching particular string...
select id,(select name from company where product.cid=company.id) as
company,name,selling_price,mrp from product where name like '$qry_string%'
But when i need to list products of specific company how can i do?
i tried the following but in vein
select id,(select name from company where product.cid=company.id) as
company,name,selling_price,mrp from product where company like '$qry_string%'
Help me
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您尝试执行的操作不需要子查询,简单的连接就足够了。试试这个:
我认为您尝试的查询的问题是您不能在
where
子句中使用作为子查询(在您的情况下为“company”)结果的字段。您可以尝试拥有
。What you are trying to do does not require a subquery, a simple join is enough. Try this:
I think the problem with the query you tried is that you cannot use fields that are the result of a subquery (in your case, "company") in the
where
clause. You might tryhaving
instead.您可以使用
You can use