mysql - how to combine tables with 1 to many relationship into 1 line of record -
mysql - how to combine tables with 1 to many relationship into 1 line of record -
i need combine 2 tables 1 many relationship using union no success.
i've been trying utilize code
select a.equipmentid, a.codename, a.name, a.labelid, a.acquisitiondate, a.description tbl_equipmentmst a.partofid = '57' union select first 1 b.warrantyid, b.startdate, b.enddate tbl_equipwarranty b inner bring together tbl_equipmentmst c on b.equipmentid=c.equipmentid c.partofid = '57' , b.servicetype='service' order b.warrantyid desc union select first 1 d.warrantyid, d.startdate, d.enddate tbl_equipwarranty d inner bring together tbl_equipmentmst e on d.equipmentid=e.equipmentid e.partofid = '57' , d.servicetype='product' order d.warrantyid desc
can help me how produce expected output in image. using firebird database. if have solution in mysql kindly tell me , sick seek find counterpart in firebird.
the secret bring together on tbl_equipwarranty twice - using 2 different aliases. 1 service warranty , 1 product warranty. can specifying servicetype part of join. next uses ansi joins work in firebird , mysql:
select a.equipmentid, a.codename, a.name, a.labelid, a.acquisitiondate, a.description, a.partofid, w1.warrantyid serviceidwarranty, w1.startdate, w1.enddate, w2.warrantyid productidwarranty, w2.startdate, w2.enddate tbl_equipmentmst inner bring together tbl_equipwarranty w1 on w1.equipmentid = a.equipmentid , w1.servicetype = 'service' inner bring together tbl_equipwarranty w2 on w2.equipmentid = a.equipmentid , w2.servicetype = 'product' a.partofid = '57'
mysql sql firebird firebird2.1
Comments
Post a Comment