Results 1 to 2 of 2

Thread: Query

  1. #1
    Join Date
    Jun 2004
    Posts
    10

    Unanswered: 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

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Code:
    select Sample_Number
      from Sample_Material 
     where Material_Number in (10,11)
    group
        by Sample_Number
    having count(distinct Material_Number)
         = 2
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •