Simple but not so

pts.
Tags:
Database
Development
IBM DB2
Oracle
SQL
Web development
I have 2 table 1) Product_Inf and 2) Product_attribute_details I have prod_key, dye_class, prod_range in both the table. Their is no relation exist between both the table than how can i find the records available in Product_Inf but not in Product_attribute_details?

Answer Wiki

Thanks. We'll let you know when a new response is added.

something like this:

select * from table1
where Productkey not in (select productKey from Table2)

Discuss This Question: 6  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • SheldonLinker
    The method last shown will work, but is not the fastest. The following is: DB2: SELECT * FROM firstTable a EXCEPTION JOIN secondTable b ON a.field=b.field Oracle: SELECT * FROM firstTable AS a, secondTable AS b WHERE a.field=b.field(+) AND b.field IS NULL SQL Server: SELECT * FROM firstTable AS a LEFT OUTER JOIN secondTable AS b ON a.field=b.field WHERE b.field IS NULL
    30 pointsBadges:
    report
  • Jigarrshah
    select PI.* from Product_Inf PI left join Product_attribute_details PAD on (PI.prod_key = PAD.prod_key) where PI.prod_key is not null or select PI.* from Product_Inf PI where not exists ( select 'x' from Product_attribute_details PAD where PI.prod_key = PAD.prod_key and PI.dye_class = PAD.dye_class and PI.prod_range = PAD.prod_range )
    0 pointsBadges:
    report
  • Vikramnag
    I would not suggest a join here. Go with either the Exists or the IN clause. Vikram Nag
    0 pointsBadges:
    report
  • Jigarrshah
    sorry, it should be, select PI.* from Product_Inf PI left join Product_attribute_details PAD on (PI.prod_key = PAD.prod_key) where PAD.prod_key is null
    0 pointsBadges:
    report
  • BeerMaker
    Hey, ilink88, since we've helped you out with your query. why don't you satisfy our curiosity here and compare the performance of the Join and "Not IN" methods. Use the show execution plan on Query Analyzer and post the results. Check your indexes, etc to see what you can do to make it fly. Cheers
    0 pointsBadges:
    report
  • Ilink88
    [...] Address: http://itknowledgeexchange.techtarget.com/itanswers/simple-but-not-so/ (0) Comments Read [...]
    0 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following