Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Help join query

Author  Topic 

CyberShot
Starting Member

2 Posts

Posted - 2010-07-30 : 14:01:39
Which invoices have involved parts whose name contains "widget" or "whatsit"? Display the invoice number and invoice date. Sort output by invoice number

I have two tables, INVOICE which contain
InvoiceNbr
InvoiceDt
TotalPrice
FK_CustomerID
FK_EMPID

and

PART
PartNBR
Description
Cost
SalesPrice

The description is the PART table contains the widget and whatsit. I am trying to make a query that displays them both. There should only be two rows returned. My where clause keeps failing when I try to return both. This is my query now

select InvoiceNbr,
InvoiceDt
FROM INVOICE, PART
WHERE PART.Description = 'widget'
AND PART.Description = 'Whatsit';

This is returning zero rows. Is this the proper way to use a join?

vijayisonly
Master Smack Fu Yak Hacker

1836 Posts

Posted - 2010-07-30 : 14:03:48
How are the INVOICE table and PART table related? I dont see any field that is common between the two.
Go to Top of Page

harrisunderwork
Starting Member

4 Posts

Posted - 2010-08-01 : 01:35:11
@CyberShot - there is no relation between two tables (atleast I cannot see it)
Go to Top of Page

GilaMonster
Master Smack Fu Yak Hacker

4507 Posts

Posted - 2010-08-01 : 02:27:45
You're going to need to find out how they're related (maybe via a third table) if you want all invoices that have those parts. Without a join, you have a Cartesian product - all possible combinations of invoice and part, which I don't think is what you want.

p.s. Is this homework? Kinda looks like it.

--
Gail Shaw
SQL Server MVP
Go to Top of Page

CyberShot
Starting Member

2 Posts

Posted - 2010-08-01 : 02:33:12
yes it is homework. I think I figured it though.
Go to Top of Page
   

- Advertisement -