I want to add multiple values of a join query in 1 single column. Is there any way to do that?
Here is a fiddle: http://sqlfiddle.com/#!9/90540/1
Here is a screen of how to result should be like http://i60.tinypic.com/5pk7yg.png "result"
Ok here is the problem, I (and many people here, I believe) doesn't have a clue what's a point of this query, what the goal you want to achieve with this.
To get desired result you can do something like this...
SELECT CASE WHEN p.id = 1 THEN p.id END AS col1,
CASE WHEN p.id = 1 THEN p.`value` END AS col2,
CASE WHEN p.id = 1 THEN (SELECT id FROM site_gender WHERE id = 2) END AS col3,
CASE WHEN p.id = 1 THEN (SELECT `value` FROM site_gender WHERE id = 2) END AS col4,
a.id, a.email
FROM site_gender AS p
JOIN user_account AS a ON p.id = a.id
but this query doesn't have a much sense, you'll get desired result but i don't know what you can do else with it.
here is the Fiddle for that to see what's happend there...
But if you change a little your table site_gender and add her a column, let's call it parent, than you will have query like this
SELECT p.id, p.value, x.id, x.value, a.id, a.email
FROM site_gender AS p
INNER JOIN site_gender AS x
ON p.id = x.parent
JOIN user_account AS a
ON p.id = a.id
Here is SQL fiddle to see how that's look like and work...
point of having parent column is that you can choose which 2 column you want to connect when you have larger table so parent column will store id of column with that column should be connected...
If you have any further question fill free to ask!
GL!
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments