mysql - Detecting empty rows in associated table and print out dummy data -


i have 2 tables one-to-many relationship. table has columns

- id - name 

table b associated table a. table b belongs table a. table b has columns

- id - tablea_id_foreignkey - timechange - status 

i want write mysql query such when table b has no associated row entries table a, dummy data printed in output particular row in table a. result like;

tablea_name 0000-00-00  00 

one able tell row in table has no associated rows dummy data. thank help.

select b.*, coalesce(a.name, '0000-00-00 00') dummy b left join on b.a_fk = a.id 

with left join rows b, regardless if there's matching row in a. if there's no matching row, null returned. coalesce() function returns first of parameters isn't null.

update: understood question wrong...

select a.*, 'hello' dummy /*with clause rows there's no match anyway*// b right join on b.a_fk = a.id b.id null 

Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -