943,694 Members | Top Members by Rank

Ad:
  • MS SQL Discussion Thread
  • Unsolved
  • Views: 573
  • MS SQL RSS
Jul 16th, 2009
0

Question about SELECT statement

Expand Post »
I have one table in this format:
Product  Component
---------------------------
A            part1
A            part2
B            part1
B            part4
A            part3
C            part5
D            part1

now I want to display product which components meet requested items, for example:
I know component are "part1" and "part3", need to show product name (that is "A").
How can I do that in SQL statement?

Thanks.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
michael123 is offline Offline
93 posts
since Jun 2005
Jul 16th, 2009
1

Re: Question about SELECT statement

SQL Syntax (Toggle Plain Text)
  1. SELECT Product FROM Table
  2. WHERE Component IN ('part1','part3')
Last edited by cgyrob; Jul 16th, 2009 at 6:53 pm.
Reputation Points: 91
Solved Threads: 18
Junior Poster
cgyrob is offline Offline
125 posts
since Sep 2008
Jul 16th, 2009
0

Re: Question about SELECT statement

How about "part1", "part3" are retrieved from SELECT statement? to use "select from table where component in (select part1 from....)"?
Also "IN(part1, part3)" is OR , not AND, right? I need "AND".
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
michael123 is offline Offline
93 posts
since Jun 2005
Jul 16th, 2009
0

Re: Question about SELECT statement

cgyrob's response was what you asked for. What is your real goal here? Or are we not understanding your problem correctly?
Featured Poster
Reputation Points: 1749
Solved Threads: 735
Senior Poster
sknake is offline Offline
3,948 posts
since Feb 2009
Jul 17th, 2009
0

Re: Question about SELECT statement

If you really want an 'AND' use an 'AND'

SQL Syntax (Toggle Plain Text)
  1. SELECT Product FROM Table
  2. WHERE Component = 'part1'
  3. AND Component ='part3'
Reputation Points: 91
Solved Threads: 18
Junior Poster
cgyrob is offline Offline
125 posts
since Sep 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in MS SQL Forum Timeline: How to open Master Database File(.mdf)
Next Thread in MS SQL Forum Timeline: Aspx page wont search a database





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC