Mysql
 sql >> Base de données >  >> RDS >> Mysql

mysql coller deux résultats ensemble (côte à côte)

create table if not exists first_40482804 (
    bla varchar(50)
) ;

create table if not exists second_40482804 (
    cla int
) ;

truncate table first_40482804 ;
truncate table second_40482804 ;

insert into first_40482804 ( bla ) values ('a') ;
insert into first_40482804 ( bla ) values ('z') ;
insert into first_40482804 ( bla ) values ('f') ;

insert into second_40482804 ( cla ) values ( 80 ) ;
insert into second_40482804 ( cla ) values ( 7 ) ;
insert into second_40482804 ( cla ) values ( 15 ) ;

set @blaRow = 0 ;
set @claRow = 0 ;

select concat( `first`.bla,',',`second`.cla) paste from
(   
    select @blaRow:[email protected]+1 `row` , bla from first_40482804
) `first`
left join 
(
    select @claRow:[email protected]+1 `row` , cla from second_40482804
) `second`
on `first`.`row` = `second`.`row`

-- résultats

paste
a,80
z,7
f,15