【问题标题】:SQL JOIN for three tables三个表的 SQL JOIN
【发布时间】:2014-11-04 10:41:54
【问题描述】:

我有三张桌子

tbl_Service

1)sId
2)Name

tbl_quatItem

1)iId
2)quat_ID
3)ser_Id

tbl_quat

1)qId
2)date
3)Name

我试过下面的说法

select s.*, q.* 
from tbl_service s, tbl_quatItem q 
where q.quatID = 1001 
and s.sId not in q.qutID 

现在我想从tbl_Service 获取不在tbl_quatItemquat_Id = qID 中的数据

【问题讨论】:

  • 祝你好运。如果您遇到困难,请回来告诉我们在哪里。
  • 我尝试过加入但它不起作用
  • 您能否通过编辑原始问题向我们展示您所做的工作。另外,这些表是如何链接的?
  • 我还是没听懂你的要求,能不能说的具体点?
  • 这很好,但是你能告诉我们你到目前为止所做的尝试吗?如果不了解您实际想要做什么,就很难解释您哪里出错了!

标签: mysql sql oracle


【解决方案1】:
select * from tbl_Service where sId not in  (select ser_Id from tbl_quat_ID where quat_Id != <qID>)

我希望 qID 是从应用程序端传递的。你只需要附加字符串即可在那里传递正确的值

【讨论】:

  • 表示查询字符串类似于 String query = "select * from tbl_Service where sId not in (select ser_Id from tbl_quat_ID where quat_Id != " + qID + ")";
猜你喜欢
  • 2011-12-22
  • 2023-03-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-12-13
  • 1970-01-01
  • 2017-07-19
相关资源
最近更新 更多