0

i have for example:

tableAaa:
id | titleSSS
1  | sfdf
2  | sdfs

tableBbb:
id | titleUUU
1  | sfdf
2  | sdfs

tableCcc:
id | titleIII
1  | sfdf
2  | sdfs

etc, for example * 10.

Is possible make something like:

SELECT title* FROM table*

If yes, how?

EDIT: i dont want use UNION and do select from each table... These table is ~100. I would like make regular expression.

2 Answers 2

1

You can do it, but you'll have to list all column and table names manually:

SELECT titleSSS FROM tableAaa
UNION ALL
SELECT titleUUU FROM tableBbb
UNION ALL
SELECT titleIII FROM tableCcc

Note that you must use UNION ALL instead of UNION or otherwise you won't get duplicate rows in the output. Read more here: http://dev.mysql.com/doc/refman/5.0/en/union.html

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

6 Comments

i dont want make select from each table... these table is ~100
@PaulAttuck then generate this SQL statement in PHP
and how can i get name table beginning of "title" from MySQL to PHP?
@PaulAttuck show tables where tables_in_<dbname> like 'table%';
thanks +1, and how to show all name columns of these table? :)
|
1

The thing require by you is might not be possible you can do as below

SELECT title1 FROM table1
union
SELECT title2 FROM table2
union
SELECT title3 FROM table3

OR

You can make use of DynamicSQL to resolve your issue easily. ans for you : How To have Dynamic SQL in MySQL Stored Procedure

3 Comments

i know, but i would like make regular expression for this. I have these table 100
how to use DynamicSQL for this? :)
@Paul Attuck - here is link for you stackoverflow.com/questions/190776/…

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.