我有 3 个这样的表:
comment
桌子 :
commentId pid sid text vid
1 1 null comment 1 1
2 null 1 comment 2 1
3 2 null comment 3 1
student
桌子:
sid firstname lastname
1 john adam
2 joan adam
professor
桌子 :
pid firstname lastname
1 mark abram
2 sean hoak
我想写一个查询,结果返回如下:
firstname lastname
mark abram
john adam
sean hoak
米
if (select query ==null)
then (select query 1)
else select (query 2)
我尝试了以下方法:
if((select pid from comment==null)
then select student.firstname , student.lastname from student where sid in (select sid from comment where vid=1)
else
(select professor.firstname ,professor.lastname from professor where pid in (select pid from comment where vid=1)
但没有运气。
任何想法如何达到想要的结果?