无需使用连接即可从两个表中获取数据 [英] Get data from two tables without using join

查看:71
本文介绍了无需使用连接即可从两个表中获取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我有两张桌子tab1和tab2。

Tab1

id姓名

1 abc

2 xyz

3 mno



tab2

id工资

1 100

2 200

3 300



我想输出如下 不使用JOIN



id姓名工资

1 abc 100

2 xyz 200

3 mno 300

解决方案

为什么不加入?

你仍然可以得到所需的结果。

试试这个 -



  SELECT  Id,Name,( SELECT  Salary  FROM  Tab2  WHERE  Tab1.Id = Tab2.Id) AS 薪资
FROM Tab1





注意:没有在SSMS中运行此quey但是类似于这应该有效。


从tab1选择id,name,salary,tab2 where tab1.id = tab2.id

但这是一种连接

Hi I have two tables tab1 and tab2.
Tab1
id Name
1 abc
2 xyz
3 mno

tab2
id salary
1 100
2 200
3 300

I want output like as follows without using JOIN

id Name Salary
1 abc 100
2 xyz 200
3 mno 300

解决方案

Why not JOIN?
You can still get the required result, though.
Try this-

SELECT Id,Name, ( SELECT Salary FROM Tab2 WHERE Tab1.Id=Tab2.Id) AS Salary
FROM Tab1



Note: Haven't runned this quey in SSMS but something like this should work.


select id,name,salary from tab1,tab2 where tab1.id=tab2.id
but this is a kind of join


这篇关于无需使用连接即可从两个表中获取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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