1

I've a database called test and i've tables called 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?

update

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

Thanks in advance!!

3
  • @zerkms:I've updated my question,Can this be done? Commented Feb 16, 2012 at 6:35
  • "SELECT column date from all tables which is in a database called test" --- it is not how Relational Databases work. You shouldn't want to do that. Could you explain why do you need that? Commented Feb 16, 2012 at 6:44
  • @user1051322: and why do you need to retrieve the date from unknown table? Commented Feb 16, 2012 at 6:46

1 Answer 1

1

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. 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 (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;

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

Also take a look at:

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

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

Sign up to request clarification or add additional context in comments.

1 Comment

:select column y from all tables that is in database table test.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.