sql - Join more than two tables -
i trying join 2 tables , in 1 table there may or may not have corresponding values.but need join table , list fields null.
i have tried join tables left join.but if 2 entries there in secoond table corresponding value of first table,then first table data displayed twice.
i need display 1 time if there 2 data in table or there no data in table,but should display null.
here sql query.
select *,incident.incident_id incidentid register_incident incident left join incident_images im on im.incident_id= incident.incident_id incident.state='active'
i need display 1 time each data if there no corresponding rows in table,but fields in second table list null.
if there more 1 row in table,then display each row in first table 1 time 1 entry in second table.
you can use select distinct 1 row eg (limiting select indicent_id ,, can add distinctcolumn need ):
select *,incident.incident_id incidentid register_incident incident left join ( select distinct incident_id incident_images incident.state='active' ) t on t.incident_id= incident.incident_id
Comments
Post a Comment