mysql - How to create left joins without repetition of rows on the left side -


i have scenario there 2 tables (tables , b) linked in 1 many relationship. row in table a, maximum number of linked rows in b two, , these 2 rows (if exist) different each other through type column value either x or y.

aid | name                            bid  | type | aid 1   | name1                             1  |  x   | 1 2   | name2                             2  |  x   | 2 3   | name3                             3  |  y   | 2 

now, want have join query 2 tables in such way rows in displayed (no repetition) , 2 columns called type x , type y hold boolean / integer value show existence of types x , y each row in a. i.e,

aid | name  | type x | type y | 1   | name1 |   x    |  null  | 2   | name2 |   x    |   y    | 3   | name3 |  null  |  null  | 

my dbms mysql.

thanks.

you have use 2 joins:

select a.*, b1.type typex, b2.type typey left join b b1 on a.aid = b1.aid , b1.type = 'x' left join b b2 on a.aid = b2.aid , b2.type = 'y' 

Comments

Popular posts from this blog

delphi - How to convert bitmaps to video? -

jasper reports - Fixed header in Excel using JasperReports -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -