SELECT Table From Select Other Table [英] SELECT Table From Select Other Table

查看:79
本文介绍了SELECT Table From Select Other Table的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从选择其他表中选择表格?



表1

==========

ID |姓名|

----------

1 |亨利

2 | Dony

----------



表2

====== =====

ID |地址|

-----------

1 |伦敦

2 |得克萨斯州

-----------

i有选择ID table2来自Select table1,如下所示:

how to select table from select other table ?

Table1
==========
ID| Name |
----------
1 | Henry
2 | Dony
----------

Table2
===========
ID| Addres|
-----------
1 | London
2 | Texas
-----------
i have select ID table2 From Select table1, like below :

SELECT ID From Table2 Where Select ID From Table1

推荐答案

由于表的关系未知,因此您的表示例和描述没有太大的作用。我只能猜测ID列,但我不确定。



如果你想加入2个表中关于匹配信息的信息,我会从内连接 [ ^ ]。



你也可以查看有关外部联接的信息,如果你想显示左表中的信息而不是正确的表,我会谷歌TSQL左外连接



PS我假设你在看SQL Server,如果我错了请告诉我,我会更新我的答案。
Your table examples and description don't give much to go on as the relationship of the tables is not known. I can only guess on the ID columns but I am unsure.

If you are looking at joining the information in the 2 tables on matching information I would start with inner join[^].

you can also look up information on outer joins, I would Google on "TSQL left outer join" if you want to show information that is in the left table but not the right table

P.S I have made an assumption that you are looking at SQL Server, If I am wrong please let know and I'll update my answer.


你可以使用 IN 子句。

从table2中选择ID为id IN(从table1中选择id,其中<< some条件>>)



相同的查询可以写成 JOIN 。你可以自己尝试一下。
You can use the IN clause.
select id from table2 where id IN (select id from table1 where <<some condition>>)

The same query can be written as a JOIN. You can try that out yourself.


这篇关于SELECT Table From Select Other Table的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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