mysql - Using inner joins gives too many results -
i'm having trouble inner joins. i'm assuming i'm making critical, yet basic error in theory.
table structure:
- bookdb - table includes data books in our library (title, barcode, check out status, etc)
- librarydb - table includes data checked out book when
- studentdb - table includes data students (name, id number, etc)
i made page listed books checked out using check out status of bookdb table. of course doesn't let me know has it.
in order display has checked out book, want call librarydb, records checked out, call studentdb, contains name, etc of student.
so made query this:
select * bookdb inner join librarydb on bookdb.barcode = librarydb.barcode inner join studentdb on librarydb.studentid = studentdb.studentid bookdb.status = '$checkinstatus' order title asc
the problem instead of getting result of person checked out recently, every person ever checked out.
i realize simple i've tried looking @ other similar posts , can't seem figure out basic problem here. realize need restrict query somehow, don't know syntax doing way want to.
thanks in advance.
edit: current output looks this:
animals in danger a1 shingen tomita 9780194233798 edit book delete book armans journey a1 ayaka morikawa 9780521184939 edit book delete book armans journey a1 ayaka morikawa 9780521184939 edit book delete book armans journey a1 naomi maki 9780521184939 edit book delete book armans journey a1 naomi maki 9780521184939 edit book delete book armans journey a1 iwamoto kazumi 9780521184939 edit book delete book armans journey a1 iwamoto kazumi 9780521184939 edit book delete book armans journey a1 kanata shokai 9780521184939 edit book delete book bens big swim od1 keiichiro takemura 9780194722674 edit book delete book bens big swim od1 keiichiro takemura 9780194722674 edit book delete book bens big swim od1 takato suzuki 9780194722674 edit book delete book
for same books, i'd output last entry each unique book:
animals in danger a1 shingen tomita 9780194233798 edit book delete book armans journey a1 kanata shokai 9780521184939 edit book delete book bens big swim od1 takato suzuki 9780194722674 edit book delete book
you can try way :
select * bookdb,librarydb,studentdb bookdb.barcode = librarydb.barcode , librarydb.studentid = studentdb.studentid , bookdb.status = '$checkinstatus' order title asc;
Comments
Post a Comment