Specifying individual fields to concatenate in a select statement works fine: SELECT CONCAT(field1,field2) as single FROM tbl_name How can I do this to concatenate all fields? ie SELECT CONCAT(*) as single FROM tbl_name?
I can't specify each and every field in the statement because I am using this statement for various tables. Edit: This doesn't work but I'd have thought something along these lines would work: SELECT concat(SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE table_name = 'tbl_name') as single FROM tbl_name ??
i think you would have to do this in two queries: $column_list = mysql_fetch_assoc(mysql_query("select group_concat(column_name) as columns from information_schema.columns where table_name='tbl_name'")); $concat_query = mysql_query("select concat({$column_list['columns']}) as single from tbl_name"); or something similar via php
heavydev's method is appropriate and can be used for this purpose. Just make sure to also add table_schema as well otherwise if same table is available in more than 1 database, you will get list of columns from all the tables modified query will be something like this... $column_list = mysql_fetch_assoc(mysql_query("select group_concat(column_name) as columns from information_schema.columns where table_schema='DB_NAME' table_name='tbl_name'")); PHP: