If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Query

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-23-04, 05:50
Thriu Thriu is offline
Registered User
 
Join Date: Jun 2004
Posts: 10
Query

Hi,
I have a table like Sample_Material
fiels are ID,Material Number and Sample Number. A sample contains number of material numbers like
ID Material_Number Sample_Number
1 10 1000
1 11 1000
1 12 1000
1 10 1001
1 13 1001
1 10 1002
1 12 1002
1 11 1002

I have to select Sample Number which contains number of material numbers when i select by material numbers. say for example if i select material numbers 10,11 means i should get only 1000 and 1002 sample number(It should not select 1001 which contain only 10) which contains these two material numbers.

I am using MySQl database.

Pls help me to make the query.
Thanks in advance,
Thiru
Reply With Quote
  #2 (permalink)  
Old 08-23-04, 07:50
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
Code:
select Sample_Number
  from Sample_Material 
 where Material_Number in (10,11)
group
    by Sample_Number
having count(distinct Material_Number)
     = 2
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On