使用join和同一列上的条件从两个表中获取数据

时间:2018-05-01 21:22:13

标签: mysql sql

Select * from AMEDIAproject_TitleManagement_TitleDetails full 
    outer JOIN AMEDIAproject_TitleManagement_TitleOwner 
    ON AMEDIAproject_TitleManagement_TitleDetails.title_owner_id = 
        AMEDIAproject_TitleManagement_TitleOwner.title_owner_id
where AMEDIAproject_TitleManagement_TitleDetails.title_code=@title_code 
    or (AMEDIAproject_TitleManagement_TitleDetails.title_code is not null)
  • 我想要的是如果我不提供title_code它应该返回所有标题代码的所有数据但是如果我指定title_code它应该返回指定title_code的数据

1 个答案:

答案 0 :(得分:1)

where AMEDIAproject_TitleManagement_TitleDetails.title_code = 
      coalesce(@title_code, AMEDIAproject_TitleManagement_TitleDetails.title_code)