开发者

How to choose field value between two fields of different tables

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;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜