954,566 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Question about SELECT statement

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.

michael123
Junior Poster in Training
94 posts since Jun 2005
Reputation Points: 10
Solved Threads: 0
 
Select Product From Table
Where Component in ('part1','part3')
cgyrob
Junior Poster
126 posts since Sep 2008
Reputation Points: 91
Solved Threads: 18
 

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".

michael123
Junior Poster in Training
94 posts since Jun 2005
Reputation Points: 10
Solved Threads: 0
 

cgyrob's response was what you asked for. What is your real goal here? Or are we not understanding your problem correctly?

sknake
Industrious Poster
4,954 posts since Feb 2009
Reputation Points: 1,764
Solved Threads: 735
 

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

Select Product From Table
Where Component = 'part1'
and Component ='part3'
cgyrob
Junior Poster
126 posts since Sep 2008
Reputation Points: 91
Solved Threads: 18
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You