azuka Posted March 25, 2006 Share Posted March 25, 2006 I have two tables I want to search for content -- One is called auth_books and the other auth_chapters. Their structures are as follows:auth_books:BookId => (int)BookName => (varchar)Description => (text)auth_chapters:ChapId => (int)ChapName => (varchar)ChapText => (text)BookId => (int)I want to search both tables and return content that contains keywords. What kind of query do I need to write? Quote Link to comment https://forums.phpfreaks.com/topic/5745-searching-multiple-tables/ Share on other sites More sharing options...
shocker-z Posted March 25, 2006 Share Posted March 25, 2006 [!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]select * FROM auth_books, auth_chapters WHEREauth_books.BookName LIKE '$search' ORauth_books.Description LIKE '$search' ORauth_chapters.ChapName LIKE '$search' ORauth_chapters.ChapText LIKE '$search'[/quote]OR a better way[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]mysql_query("select * FROM auth_books, auth_chapters WHERE '$search' IN (auth_books.BookName, auth_books.Description, auth_chapters.ChapName, auth_chapters"));[/quote]Just make a var called $search with the search in :)Should do the job :) Quote Link to comment https://forums.phpfreaks.com/topic/5745-searching-multiple-tables/#findComment-20496 Share on other sites More sharing options...
Barand Posted March 25, 2006 Share Posted March 25, 2006 The query has no join condition specified.If you have 50 books with 10 chapters each then you will have 500 rows in the chapters table and, if you join on BookId, (WHERE auth_books.BookId = auth_chapters.BookId) you would be searching 500 rows.Because no join is specified it will join every book row with every chapter row so you will be searching 25,000 rows. Expect some duplication of the search results. Quote Link to comment https://forums.phpfreaks.com/topic/5745-searching-multiple-tables/#findComment-20524 Share on other sites More sharing options...
azuka Posted March 25, 2006 Author Share Posted March 25, 2006 Thanks a lot for all the help -- I'm using full-text search instead. I noticed that if I don't specify 'IN Boolean Mode' I don't get any results -- is it because of the character sets I'm using? Which character set is good for case-insensitive search? Quote Link to comment https://forums.phpfreaks.com/topic/5745-searching-multiple-tables/#findComment-20727 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.