【问题标题】:SQL select records based on collection result from another querySQL 根据另一个查询的收集结果选择记录
【发布时间】:2017-02-03 20:02:06
【问题描述】:

这一步我有点卡住了:有两个表: 预订(bookingId、id、userId) timetableSlot (id,classId)

“id”链接两个表。

任务 - 显示所有课程,由用户预订。 在 Servlet 中,我可以从预订表中选择特定用户的所有预订:

    int userId=Integer.parseInt(request.getParameter("loggedInUserId"));

    BookingDB allUserBookings = new BookingDB();
    Collection<BookingDB> userBookings = new ArrayList<BookingDB>();
    userBookings = allUserBookings.displayUserBookings(userId);

结果是一个用户预订的记录集合,其中包含许多时间表时段 ID。如何传递所有这些 id 以从 timetableSlot 表中选择相应的记录?根据收藏选择收藏?谢谢你

【问题讨论】:

  • 您的代码中没有 SQL。你确定这是正确的标签吗?如果是这样,您可能希望显示您正在使用的查询。
  • 您好,此代码来自 servlet,用于检索所有预订。我为此使用了这个 sql:SELECT * FROM booking where userId=?它返回集合
  • 下一步怎么做:SELECT * FROM timetableSlot where id=results from previous query?
  • SELECT * FROM timetableSlot where id in (select id from "previous query")
  • 不要在 cmets 中发布代码。 edit你的问题。另外:您使用的是哪个 DBMS?表的定义是什么?查询的预期输出是什么?

标签: sql


【解决方案1】:

SELECT * FROM ttslot ID IN (

从预订中选择 id WHERE booking.userId=76 )

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-08
    • 1970-01-01
    • 2017-11-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多