Community journal

The latest from the MySQL community

Ideas, releases, practical guides, and perspectives from the people building with MySQL.

Follow the feed
Showing entries 1 to 1 of 1 « Previous | Next »
Displaying posts with tag: Column Names (reset)
A function to get all the columns of any table from any database

Permalink: http://bit.ly/VP174V



Certain complex MySQL SELECT and subquery statements will not allow the use of the * wildcard and you will need to fill in the entire column list of a given table. Consider the following simplified example, a SELECT statement that contains 3 columns. The asterisk here refers to all columns, which is actually the 3 columns listed in the GROUP BY clause:

SELECT
IF(
EXISTS(
SELECT *
FROM (
SELECT *
FROM `dbName_A`.`tableName_A`
UNION ALL
SELECT *
FROM `dbName_B`.`tableName_B`
AS `compareTables`
GROUP BY `column_1`, `column_2`, `column_3`
HAVING COUNT(*) = 1),
1, 0);


Imagine if it were dozens of columns instead of just 3. You can't simply put in the * wildcard like 'GROUP BY * '. The above example will not …

[Read more]