I have two tables with fields tbl_room(room_id,cat_id,room_price) and tbl_c开发者_开发问答ategory(cat_id,cat_price).
Is there any way to check and if room_price is null then put the value of cat_price
select price(if room_price is null show cat_price else room_price)
Sth like that
Yes, assuming the relation between tbl_room to tbl_category
is 1:1
relationship
select
tr.room_id, tr.cat_id,
coalesce(tr.room_price, tc.cat_price) as price
from tbl_room as tr
left join tbl_category tc
on tr.cat_id=tc.cat_id;
精彩评论