Hi,
I've got 3 tables:
1.) book: BookID, Title
2.) bookcomment: BookCommentID, BookID, ContactID, Comment
3.) responsibilityl og: ResponsibilityI D, BookID, ContactID, DataFrom, DateTo
Relationships:
book and bookcomment: one to one
book and responsibilityl og: one to many
I want a query that returns book.Title and bookcomment.Com ment WHERE BookID=1 AND ContactID=2 regardless if responsibilityl og returns a record,
AND
the query must return all the records with fields book.Title, responsibilityl og.DataFrom and responsibilityl og.DateTo WHERE BookID=1 AND ContactID=2 regardless if bookcomment returns a record
The following query only returns data if there is a record in bookcomment AND responsibilityl og that meet the conditions because of my AND statement, but I don't know how to rectify this. If I use OR in place of AND, I do not get the desired result.
[code=mysql]
rs = st.executeQuery ("select b.Title, rl.DateFrom, rl.DateTo, c.Comment from book b left join responsibilityl og rl on b.BookID = rl.BookID left join bookcomment c on c.BookID = b.BookID WHERE rl.ContactID='" + ContactID + "' AND c.ContactID='" + ContactID + "'");
[/code]
I've got 3 tables:
1.) book: BookID, Title
2.) bookcomment: BookCommentID, BookID, ContactID, Comment
3.) responsibilityl og: ResponsibilityI D, BookID, ContactID, DataFrom, DateTo
Relationships:
book and bookcomment: one to one
book and responsibilityl og: one to many
I want a query that returns book.Title and bookcomment.Com ment WHERE BookID=1 AND ContactID=2 regardless if responsibilityl og returns a record,
AND
the query must return all the records with fields book.Title, responsibilityl og.DataFrom and responsibilityl og.DateTo WHERE BookID=1 AND ContactID=2 regardless if bookcomment returns a record
The following query only returns data if there is a record in bookcomment AND responsibilityl og that meet the conditions because of my AND statement, but I don't know how to rectify this. If I use OR in place of AND, I do not get the desired result.
[code=mysql]
rs = st.executeQuery ("select b.Title, rl.DateFrom, rl.DateTo, c.Comment from book b left join responsibilityl og rl on b.BookID = rl.BookID left join bookcomment c on c.BookID = b.BookID WHERE rl.ContactID='" + ContactID + "' AND c.ContactID='" + ContactID + "'");
[/code]
Comment