Mysql search query two columns

前端 未结 3 1072
悲哀的现实
悲哀的现实 2021-01-24 10:40

I\'m bulding a search function for my web site and wish to search by two columns: title and author.

Query:

SELECT title, bookID, publisher, pubDate, boo         


        
相关标签:
3条回答
  • 2021-01-24 10:59
    SELECT title, bookID, publisher, pubDate, book_image, books.authorID, authors.author 
    FROM books, authors 
    WHERE books.authorID = authors.authorID 
            AND (title LIKE '$queryString%' OR author LIKE '$queryString%')LIMIT 5
    

    this should do the work

    0 讨论(0)
  • 2021-01-24 11:02

    Try it out:

    SELECT bk.title, bk.bookID, bk.publisher, bk.pubDate, bk.book_image, bk.authorID, au.author
    FROM books bk,  authors au
    WHERE bk.authorID = au.authorID AND bk.title LIKE '$queryString%' OR au.author LIKE '$queryString%' LIMIT 5
    
    0 讨论(0)
  • 2021-01-24 11:08

    Try below :

    SELECT title, bookID, publisher, pubDate, book_image, books.authorID, authors.author 
    FROM books left join  authors on  books.authorID = authors.authorID 
    WHERE (title LIKE '$queryString%' OR author LIKE '$queryString%') LIMIT 5
    

    I would like to suggest you to use fulltext search in mysql.That will be more faster and efficient

    0 讨论(0)
提交回复
热议问题