Click here to Skip to main content
15,881,248 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I Want to fetch Record from Four tables Named AS Book_Master,BookIssue_Master,BookEntity_Master,Penalty_Master Having Foreign key BI_SerialNo,BE_SerialNo,BK_SerialNo
But My Query unable to Fetch Required data. My Query is follows

SQL
SELECT BK_BookName,BK_BookPublication,BK_SerialNo,BI_SerialNo,BI_BookEntityID,
BI_BookIssueDate,BI_BookReturnedOn,PN_BookIssueID,PN_SerialNo,PN_BookIssueID,
PN_PenaltyAmountInWords,BE_SerialNo,BE_BookID FROM Book_Master,BookIssue_Master,
BookEntity_Master,Penalty_Master WHERE BI_SerialNo=PN_BookIssueID
AND BI_BookENtityID=BE_SerialNo
AND BE_BookID = BK_SerialNo
AND BI_IsPenalty IN('N')



It Fetches All data From Database tables,Please Suggest me to get required data
Posted
Updated 25-Jan-14 0:16am
v2

1 solution

Try using a JOIN:
SQL
SELECT tab1.ID, tab1.Value, tab2.Value
FORM Table1 tab1
JOIN Table2 tab2
ON tab1.ID=tab2.IDInTable1
WHERE tab2.SelectOnThis=666

Without knowing a lot more about your various tables and how they are interconnected, I can;'t give you any exact SQL for your precise need, but that should give you the idea.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900