user82302124
user82302124

Reputation: 1143

Masking values in SQL select return

This is an odd question, but I was wonder if you could display one column in the results, but really have another column as the values (MYSQL). Suppose I have this table:

ID   Name
1    Soccer
2    Football

I was wonder if it was possible to select all IDs from this table (select ID from table), but the results would display the name instead.

Or is it possible to display as the result (as a single column)?:

1 (Soccer)
2 (Football)

Upvotes: 0

Views: 98

Answers (2)

John Woo
John Woo

Reputation: 263743

This will have results concatenated into single column.

SELECT CONCAT(ID, ' (', Name, ')')
FROM tableName

SQLFiddle Demo

Upvotes: 1

Salil
Salil

Reputation: 47492

SELECT ID, CONCAT("(", name, ")") FROM <TABLENAME>

Upvotes: 4

Related Questions