从数据库中选择所有表

从数据库中选择所有表

本文介绍了Mysql-从数据库中选择所有表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为 test 的数据库,还有一个名为 x,y,z 的表.

I've a database called test and i've tables called x,y,z.

我如何选择 x,y,z 并且有一列名为 date IN X,Y,Z 检查是否存在特定日期.

How do i select x,y,z and there is a column called date IN X,Y,Z check whether there is a particular date.

是否有任何内置函数可以做到这一点?

Is there any build in function that does this?

更新

从名为 test 的数据库中的所有表中选择列日期

SELECT column date from all tables which is in a database called test

提前致谢!!

推荐答案

据我所知,在 SQL 中你不能'选择表',你可以选择一些一次来自一个或多个表的列.此类查询的结果是您从中检索数据的另一个表(临时表).

As far as I know, in SQL you cannot 'select a table', you can select somecolumn(s) from one or many tables at once. The result of such a query is an another table (temporary table) that you retrieve the data from.

请更具体地说明您想要做什么(例如:我想从表 'tableA' 中选择列 'z' 和从表 'tableB' 中选择列 'y'") - 那么我确定你的问题有一个非常简单的答案:)

Please be more specific about what exactly you want to do (e.g.: "I want to select a column 'z' from table 'tableA' and column 'y' from table 'tableB'") - then I'm sure your question has a pretty simple answer :)

SELECT x.date AS x_date, y.date AS y_date, z.date AS z_date FROM x,y,z;

产生一个结果:

+---------+---------+---------+
| x_date  | y_date  | z_date  |
+---------+---------+---------+
|         |         |         |
|         |         |         |
+---------+---------+---------+

或者,您可以通过使用查询获得一列中的所有内容:

Alternatively you can get everything in one column by ussuing a query:

SELECT date FROM x
UNION ALL
SELECT date FROM y
UNION ALL
SELECT date FROM z;

产生一个结果:

+-------+
| date  |
+-------+
|       |
|       |
+-------+

在上面的示例中,您还会在单列中获得重复的值.如果您想避免重复,请将UNION ALL"替换为UNION"我仍然不确定我是否理解了您真正想要达到的目标,但我仍然希望能有所帮助

In the example above you would get also duplicate values in the single column. If you want to avoid duplicates replace 'UNION ALL' with 'UNION'I'm still not sure if I undestood what you really want ot achieve, but I still hope that helps

另请看:

http://www.w3schools.com/sql/sql_union.asp

http://www.sql-tutorial.net/SQL-JOIN.asp

这篇关于Mysql-从数据库中选择所有表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 04:23