views:

26

answers:

1

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 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)

+1  A: 

You can use IFNULL(col1, col2). If col1 is not null, it is returned. If col1 is null, col2 is returned.

Max Shawabkeh
excellent. can i write a select statement in the params? do i have to do ifnull(a, b) select name1 as a ..... basically i want to know if ifnull is before the select or if the select is inside it (or if i need to google an example)
acidzombie24
Your question is pretty confusing. Could you describe exactly what you are trying to accomplish, and what are the desired actions taken in each case?
Max Shawabkeh