Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

majacirkova's avatar

Returning from 3 select attributes table columns and show result into one column

Hello guys what i want to return is this : I have 3 tables

table1 id1

table2 id2

table3 id3

So , I want to select id1, id2 and id3 and show in one column like this: id1_id2_id3

For example if data into tables are like this:

table1    table2    table3
1       1       1
2       2       2

So I want the result to be like this:
1_1_1
2_2_2

.....

Thanks a lot.

0 likes
5 replies
bestmomo's avatar

If there is no relation between tables you must make 3 queries and sort your concatenation with a loop on results.

majacirkova's avatar

No i have relations , i solve it like this:

select concat(distribution_id , '_',message_type_id, '_',language_id ) as full_name from `distribution_combination_rule`
pmall's avatar

Please show us a real world example, with entity name, etc.

majacirkova's avatar

I execute this sql query:

   select    CONCAT(  (select distribution from distribution,distribution_combination_rule where distribution.id = distribution_combination_rule.distribution_id), 
               (
select type  from message_type,distribution_combination_rule where message_type.id = distribution_combination_rule.message_type_id
),
                (
select language 
from language ,distribution_combination_rule where
language.id = distribution_combination_rule.language_id))
               

I don't know why this returns this errors: #1242 - Subquery returns more than 1 row

Please or to participate in this conversation.