子查询问题(在where条件中不传递参数) [英] sub query problem (without passing parameter in where condition)
问题描述
尊敬的先生,
我需要在选择查询中生成子查询,以获取我的主表即市场表的所有记录.这是代码
市场表
Mkid价格折扣
1 100 2
2 150 0
3 100 0
产品表
< pre lang =" >
Mkid名称
1电子
2项运动
3种食物
< /pre >
我需要选择市场表的所有行和产品表的名称.
所以我用这个查询
选择价格,折扣,(选择名称' 来自产品其中 MKid = 1)来自市场
因此,在上面的子查询中,我已经传递了mkid参数,是否可以不用Mkid来获取名称.
所以我需要价格折扣名称的所有行,而无需在where子句中传递参数或mkid
请帮助
尝试一下:
SELECT 价格,折扣,名称 FROM 市场 左 JOIN 产品 ON 市场.MKid= product.MKid
根据我的理解,如果您正在寻找类似的输出,
价格折扣名称 100 2 电子产品 150 0 运动 100 0 食物
最好的方法是联接两个表.
希望对您有所帮助.
尝试一下
选择市场价格,m.discount,商品名称来自市场m 内部 加入产品p 在上. MKid = p.MKid
看到这个
http://stackoverflow. com/questions/9393207/无法解决sql-latin1-general-cp1-ci-as-and [ ^ ]
Dear sir,
i need to generate sub query in select query that fetch all record of my main table that is market table. here is code
Market table
Mkid price discount
1 100 2
2 150 0
3 100 0
Product table
<pre lang="SQL">
Mkid Name
1 Electronic
2 sports
3 Foods
</pre>
i need to select all rows of market table and name from product table.
so i use this query
select price, discount,(select name as 'name' from product where MKid=1) from market
so in above sub query i had pass mkid parameter, is there way to fetch name without using Mkid.
so i need all rows of price discount name without passing parameters or mkid in where clause
please help
Try this:
SELECT price, discount, name FROM market LEFT JOIN product ON market.MKid = product.MKid
Hi,
As per my understanding , if you are looking for a output like,
price discount name 100 2 electronics 150 0 sports 100 0 foods
Best way is to join the 2 tables.
Hope this helps.
Try this
select m.price, m.discount,p.name from market m inner join product p on m.MKid=p.MKid
[EDIT]
see this
http://stackoverflow.com/questions/9393207/cannot-resolve-the-collation-conflict-between-sql-latin1-general-cp1-ci-as-and[^]
这篇关于子查询问题(在where条件中不传递参数)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!