简体   繁体   English

MySQL-从数据库中选择所有表

[英]Mysql-Select all tables from a database

I've a database called test and i've tables called x,y,z. 我有一个名为test的数据库,还有一个名为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. 我如何选择x,y,z,然后有一个称为日期IN X,Y,Z的列,检查是否存在特定日期。

Is there any build in function that does this? 有没有内置函数可以做到这一点?

update 更新

SELECT column date from all tables which is in a database called test 从名为test的数据库中的所有表中选择SELECT列日期

Thanks in advance!! 提前致谢!!

As far as I know, in SQL you cannot 'select a table', you can select some column(s) from one or many tables at once. 据我所知,在SQL中您不能“选择一个表”,您可以一次从一个或多个表中选择一些列。 The result of such a query is an another table (temporary table) that you retrieve the data from. 这样的查询结果是另一个表(临时表),您可以从中检索数据。

Please be more specific about what exactly you want to do (eg: "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 :) 请更确切地说明您要执行的操作(例如:“我想从表'tableA'中选择列'z',从表'tableB'中选择列'y'”)-然后,我确定您的问题已经解决了一个很简单的答案:)

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

That produces a result: 产生结果:

+---------+---------+---------+
| 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;

That produces a result: 产生结果:

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

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 如果您想避免重复,请将“ UNION ALL”替换为“ UNION”,我仍然不确定我是否了解您真正想要实现的目标,但我仍然希望能对您有所帮助

Also take a look at: 还可以看看:

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

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

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

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