Paul Attuck
Paul Attuck

Reputation: 2269

Regular expression in MySQL / SQL?

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.

Upvotes: 0

Views: 135

Answers (2)

Pranay Rana
Pranay Rana

Reputation: 176896

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

Upvotes: 1

dorsh
dorsh

Reputation: 24710

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

Upvotes: 1

Related Questions