I'm not sure if this is possible but is there a way to select A unless its null then select B instead?
I am writing a trigger, my code is
insert into tbl_a(userid, obj)
select p.author, new.id
FROM开发者_C百科 user_comment AS p
WHERE p.id=new.parent
however new.parent
is a nullable long (i'll switch to foreign key once supported in system.data.sqlite)
if its null i get 0 results and no insert. I would like to use join media as m on m.id=new.media_id
and return m.user_id
if new.parent
is null. So how do i write the select to return m.author
if parent isnt null (which i'll return p.author
like the above)
You can use IFNULL(col1, col2)
. If col1
is not null, it is returned. If col1
is null, col2
is returned.
精彩评论