如何从不同的表中获取数据,比较不同表中的不同列 [英] how to get data from different table comparing different columns in different table

查看:93
本文介绍了如何从不同的表中获取数据,比较不同表中的不同列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两张桌子 tbl_addpost tbl_addcatg



我想从 tbl_addcatg 中选择列catg时从 tbl_addpost 获取数据但是我们有子类型具有列名类别,它应该比较来自tbl_addcatg的 catg 和类别列,并显示来自 tbl_addpost 比较类别列。

 选择 * 来自 tbl_addpost 其中 category =(选择类别来自 tbl_addcatg 其中 catg = '  Mobiles& ;平板电脑'



错误

消息 512 ,等级 16 ,状态 1 ,行 1  
子查询返回的值超过 1 值。 子查询如下=,!=,





http:// patakaro.com/ref1.jpg



提前致谢。

解决方案

引用:

子查询返回的值超过1。

很清楚,对吧?



以下子查询...

选择类别来自 tbl_addcatg 其中​​ catg = ' 手机和平板电脑



为您返回多个类别,您无法分配多个类别使用=运算符进行单个列进行比较。



如果你想比较wi所有类别,然后尝试使用 IN 运算符...

 选择 * 来自 bl_addpost 其中​​类别 IN 选择类别来自 tbl_addcatg 其中 catg = '  Mobiles&片剂


I have two tables tbl_addpost and tbl_addcatg

I want to get data from tbl_addpost when column catg is selected from tbl_addcatg but we have subtype with column name category it should compare catg and category column from tbl_addcatg and display relevant data from tbl_addpost comparing category column.

select * from tbl_addpost where category=(select category from tbl_addcatg where catg='Mobiles & Tablets')


error

Msg 512, Level 16, State 1, Line 1
Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=,



http://patakaro.com/ref1.jpg

Thanks in advance.

解决方案

Quote:

Subquery returned more than 1 value.

Quite clear, right?

The following Sub Query...

(select category from tbl_addcatg where catg='Mobiles & Tablets')


returns you many Categories and you can't assign many Categories to a single Column with "=" operator for comparison.

if you want to compare with all the Categories, then try to use IN operator like...

select * from bl_addpost where category IN (select category from tbl_addcatg where catg='Mobiles & Tablets')


这篇关于如何从不同的表中获取数据,比较不同表中的不同列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆