English 中文(简体)
如何写这5张表格的问答?
原标题:How to write SQL query for these 5 tables?
  • 时间:2009-09-04 19:31:11
  •  标签:

I am writing an application that helps book exchange between users. I am using PHP and MySQL, and I am pretty new to them both.

表2

  1. 用户:用户属性(用户_id、姓名、出生......等)。

  2. 书籍:具有图书属性(书目、名称、作者、出版商等)。

  3. 副本:是书籍的实际复制件(复印件、状况、评论等)。

  4. 用户_copy:描述哪些用户持有该拷贝,由用户信息数据库和复印件组成。

  5. 复印件:是复印件和书籍的链接,由复印件和图书信息数据库组成。

My question is: what is the easiest and most efficient statement for getting the book attributes and copy attributes for each copy that a user holds?

最佳回答

您需要加入你们感兴趣的所有表格:书本、复印本、用户版和书本。 用户持有的所有复制件的回归特性的电子数据表可考虑:

SELECT   B.bookID
       , B.name
       , B.author
       , B.publisher
       , C.condition
       , C.comments
       -- you may get other fields that you are interested in here..
  FROM book B
       INNER JOIN copy_book CB ON B.bookID = CB.bookID
       INNER JOIN user_copy UC ON UC.copyID = CB.copyID
       INNER JOIN copy C ON C.copyID = UC.copyID
  WHERE UC.userID = <the user Id that you want>

我希望,我非常清楚地说明发言的内容,但如果有问题,请问。

问题回答

暂无回答




相关问题
热门标签