-2

我正在研究图书馆管理并制作报告,我想从 2 个不相互关联的表中获取数据,issueDataissueRecord.

记录包含以前的图书发行数据,而数据表仅包含当前的图书发行报告。

简单地说,我想合并这两个查询,即

  1. Select * From issueRecord where issueDate = '19/07/2013'.
  2. Select * From issueData where issueDate = '19/07/2013'.

请帮忙。

4

2 回答 2

1

If your question was more clear we would be able to help more.

From what I understand you are trying for a union all or union. There is also a chance for cross join also, but that may not be the result you wanted.

There are answers for Union and union all, But I would suggest you to use like the below

Select 'Record', Field_1, Field_2, Field_3 From issueRecord where issueDate = '19/07/2013'
UNION
Select 'Data', Field_A, Field_B, Field_C From issueData where issueDate = '19/07/2013'

With this addition you can find which data is from which table.

In addition to this you can also use cross join

select * from issueRecord  CROSS JOIN issueData

but check the data what you are getting.

于 2013-10-08T12:38:19.357 回答
1

您的问题不是很清楚,但似乎您正在寻找UNIONorUNION ALL查询。

假设您想要的是一个包含每个表中的记录的单个结果集,但您没有尝试将两个表合并到一行中,则语法将类似于以下行:

Select Field_1, Field_2, Field_3 From issueRecord where issueDate = '19/07/2013'
UNION
Select Field_A, Field_B, Field_C From issueData where issueDate = '19/07/2013'

从两个表中选择的列的类型和顺序必须匹配。 UNION会将相同的记录折叠到一个输出行中,就像一个不同的子句一样,同时UNION ALL将包含每个查询的每条记录。

于 2013-10-08T12:27:51.573 回答