sql - Joining Multiple Tables - Oracle -


i'm studying multiple table joins week , have odd results being returned. here scenario...

using correct tables, create query using traditional join operation list customer first , last name, book title, , order date (formatted mm/dd/yyyy alias of “order date”) customers have purchased books published 'printing us'.

with database i'm querying against, correct tables query book_customer, books, book_order, , publisher. statement have written returns information need, returning 5900 records. don't see how can right. publisher, printing us, has 14 books listed in database , there 20 customer records, if every customer purchased every printing book, return 280 records total. yet can't figure out have wrong. statement listed below.

select bc.firstname, bc.lastname, b.title, to_char(bo.orderdate, 'mm/dd/yyyy') "order date", p.publishername book_customer bc, books b, book_order bo, publisher p where(publishername = 'printing us'); 

anyone have thoughts on i'm missing here??

thanks.

i recommend in habit, right now, of using ansi-style joins, meaning should use inner join, left outer join, right outer join, full outer join, , cross join elements in sql statements rather using "old-style" joins tables named in from clause , join conditions put in the where clause. ansi-style joins easier understand , less miswritten and/or misinterpreted "old-style" joins.

i'd rewrite query as:

select bc.firstname,        bc.lastname,        b.title,        to_char(bo.orderdate, 'mm/dd/yyyy') "order date",        p.publishername book_customer bc inner join books b   on b.book_id = bc.book_id inner join  book_order bo   on bo.book_id = b.book_id inner join publisher p   on p.publisher_id = b.publisher_id p.publishername = 'printing us'; 

share , enjoy.


Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -