简体   繁体   English

在不加入sql的情况下获取所有记录

[英]get all record without join in sql

i have two tables table1 and table2, table1 in 10 filed available and tbale2 in 6 filed available.but no any relation between them.我有两个表 table1 和 table2,table1 在 10 归档可用和 tbale2 在 6 归档可用。但它们之间没有任何关系。

i want to get all record from both table.我想从两个表中获取所有记录。

Use cross join使用交叉连接

Select t.*,t1.* from table t cross join table1 t1

If you want all the records in the same table use the above query it will join and give m*n rows where m and n are number of rows in the tables如果您希望同一个表中的所有记录使用上面的查询,它将连接并给出m*n行,其中 m 和 n 是表中的行数

You can use union all if you want all the results added m+n number of results如果您希望将所有结果添加m+n个结果,您可以使用union all

Select * from table
Union all
Select * from table1

You need to specify the columns if you need specific columns from both tables.如果您需要两个表中的特定列,则需要指定列。 Or if you have different number of columns in the tables或者,如果表中有不同数量的列

If you have at least some common columns, you can union them together.如果您至少有一些公共列,则可以将它们合并在一起。 For example:例如:

Table1表格1

Name Description Quantity Price名称 描述 数量 价格

Table2表2

Name Description OrderDate Blah BlahBlah名称 描述 OrderDate Blah BlahBlah

You can do something like this:你可以这样做:

SELECT Name, Description FROM Table1 
UNION ALL 
SELECT Name, Description FROM Table2

That would give you a result set with 2 columns (Name, Description, OrderDate) that is made up of rows from both Table1 and Table2这将为您提供一个由表 1 和表 2 中的行组成的 2 列(名称、说明、订单日期)的结果集

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM