Help with mySQL query?
Posted: Wed Sep 22, 2004 10:54 am
I am trying to perform an SQL query on a book library and my SQL is not that good - can anyone help? I have 3 tables - books, subjects(keywords) and booksubjects(keywords associated with books). I want to return a result which searches Book.Title(string) and Subjects.Subject(string) for the occurence of '%word%', so I came up with:
їcode]select * from Books B,Subjects S,BooksSubjects BS
where B.ISBN = BS.ISBN and BS.SubjectID = S.SubjectID and
B.Title LIKE '%word%' or S.Subject LIKE '%word%'ї/code]
My problem is that some books don't have an associated BookSubject record and therefore do not generate a result to search. I have looked at LEFT JOIN but don't know how to perform one across 3 tables...help please!
їcode]select * from Books B,Subjects S,BooksSubjects BS
where B.ISBN = BS.ISBN and BS.SubjectID = S.SubjectID and
B.Title LIKE '%word%' or S.Subject LIKE '%word%'ї/code]
My problem is that some books don't have an associated BookSubject record and therefore do not generate a result to search. I have looked at LEFT JOIN but don't know how to perform one across 3 tables...help please!