Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

A simple JOIN query

Status
Not open for further replies.

Idee

Programmer
Jul 8, 2003
51
NZ
My SQL query is

SELECT distinct a.optionid,b.id,optionname
FROM Price a
Right JOIN Option_Type b
ON a.optionid = b.id
WHERE a.HId = 3

Price table stores the options for the HId 3 along with the price. In Option_Type table, I have options but no main HId field.

If I have added price for the options (suppose there are three options), it will add three records in Price table. But now if I add another option, a record will be added to Option_Type, it will have four records whereas Price still has three records and my above query returns three records. How do I get all the four records even if there is no price for a record?

Thanks
 
Your WHERE clause is looking for a specific value in the Price table. If you add a record in the Option_Type table but no corresponding record in the Price table, it will be filtered out because the nonexistant a.HId field does not have a value of 3.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top