SQL SELECT查询无法正常工作-无法找到错误 [英] SQL SELECT query not working - unable to find error

查看:89
本文介绍了SQL SELECT查询无法正常工作-无法找到错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下select查询是从多个表tbl_bookstbl_authortbl_books_subject

The following select query is to search a keyword 'law' from multiple tables tbl_books, tbl_author and tbl_books_subject

SELECT *
FROM tbl_books p, tbl_books_author d, tbl_books_subject m
WHERE p.title = 'law'
   OR d.author = 'law'
   OR m.subject = 'law'
LIMIT 0,30

此查询给出错误.请帮帮我.

This query is giving error. Please help me with it.

推荐答案

您可以在单个查询中实现该功能,但需要在其他表中具有一些外键.在这里检查下面的代码.

You can achieve that in single query but you need to have some foreign key in other tables. Here check the code below.

SELECT b.*, ba.*, bs.* FROM tbl_books as b
    FULL OUTER JOIN tbl_books_author as ba ON ba.book_id=b.id
    FULL OUTER JOIN tbl_books_subject as bs ON bs.book_id=b.id
WHERE b.title LIKE 'law' OR ba.author LIKE 'law' OR bs.subject LIKE 'law' LIMIT 0, 30;

深入查看查询,您会发现我已经使用 tbl_books.id 进行了联接,这些联接应该在其他表中以标识该特定记录.

look at the query deeply you can see I have used tbl_books.id to make joins which should be in other tables to identify that particular records.

希望这对您有所帮助.

这篇关于SQL SELECT查询无法正常工作-无法找到错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆