Hi guys,

im kind of curious, is there a query or some way to fuse two colums like
select a.col1,b.col1 from table1 a left join table2 b on a.id=b.table_a_id
then as a result i want to display only one column containing a.col1,b.col1

thanks =)

Recommended Answers

All 10 Replies

select CONCAT(a.col1, ', ', b.col1) AS `fused` from table1 a left join table2 b on a.id=b.table_a_id

thanks for the try =)
what i want is 1 value per column not two separated in any delimeter

thanks for the try =)
what i want is 1 value per column not two separated in any delimeter

So if one column contained 'hot' and the other contained 'dog' you'd want 'hotdog', correct? If that's the case then blocblue's solution is correct. Merely remove the delimiter from the CONCAT function.

SELECT
  CONCAT(a.col1, b.col1) AS fused
FROM table1 AS a
LEFT JOIN table2 AS b
  ON a.id = b.table_a_id

no what i want is if one column contained 'dog' and the other column contan 'hot'
i want to display one column only; like

|tbl|

|dog|
|hot|

That's not what your original question asked for. If you want values from two different columns to display in the same column on seperate rows check out UNION instead.

You need to post more information about you database schemas if you require help with the query.

yah sorry i think this line gets my problem differnce to you
select a.col1,b.col1 from table1 a left join table2 b on a.id=b.table_a_id

thanks anyway =)

That's what you posted in your OP, which consequently you said isn't what you want.

Can you put the data into context? What is the relationship between table 1 and 2 for you to need a left join rather than inner join? Without explaining that, I can only assume the result you want is:

SELECT a.col1 FROM table1 a LEFT JOIN table2 b ON (a.id = b.table_a_id)

UNION 

SELECT b.col1 FROM table1 a LEFT JOIN table2 b ON (a.id = b.table_a_id)

However, this will include NULL values where there isn't a joining value in table b.

commented: for your patience :) +0

hi just mail me whatever you have doubts

Or how about you don't, and instead keep all the help and queries here on DaniWeb instead...

thanks blocblue =)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.