PHP mysql 三张表怎么关联查询
通过post获取readerid和条码,并作为条件进行三表关联查询SELECTbookinfo.isbn,booknotes.tiaoma,bookinfo.title,...
通过 post 获取 readerid 和 条码,并作为条件进行 三表关联查询
SELECT bookinfo.isbn,booknotes.tiaoma,bookinfo.title,bookinfo.price,booknotes.bdate,booknotes.rdate FROM (bookid INNER JOIN booknotes ON bookid.tiaoma=booknotes.tiaoma) INNER JOIN bookinfo ON bookid.isbn=bookinfo.isbn WHERE booknotes.readerid=".$_POST['readerid']."AND booknotes.tiaoma=".$_POST['tiaoma'];
以上查询失败,要怎么修改,但只有一个 readerid的条件,能查询到 展开
SELECT bookinfo.isbn,booknotes.tiaoma,bookinfo.title,bookinfo.price,booknotes.bdate,booknotes.rdate FROM (bookid INNER JOIN booknotes ON bookid.tiaoma=booknotes.tiaoma) INNER JOIN bookinfo ON bookid.isbn=bookinfo.isbn WHERE booknotes.readerid=".$_POST['readerid']."AND booknotes.tiaoma=".$_POST['tiaoma'];
以上查询失败,要怎么修改,但只有一个 readerid的条件,能查询到 展开
2个回答
展开全部
你这个不能这样查询,利用中间表(bookinfo)关联其它两表bookid booknotes
select bookinfo.isbn,booknotes.tiaoma,bookinfo.title,bookinfo.price,booknotes.bdate.booknotes.rdate from bookinfo left join bookid on bookinfo.isbn=bookid.isbn left join booknotes on bookinfo.id=booknotes.id;
select bookinfo.isbn,booknotes.tiaoma,bookinfo.title,bookinfo.price,booknotes.bdate.booknotes.rdate from bookinfo left join bookid on bookinfo.isbn=bookid.isbn left join booknotes on bookinfo.id=booknotes.id;
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询