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.

Recommended Answers

All 4 Replies

Select Product From Table
Where Component in ('part1','part3')
commented: good answer +4

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

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

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

Select Product From Table
Where Component = 'part1'
and Component ='part3'
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.