select values common in > 1 row in a table

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • SSG001
    New Member
    • Oct 2007
    • 110

    #1

    select values common in > 1 row in a table

    I have a table which has different products and materials required to make those prodcuts something like this
    prodcut material qty
    prod1 mat1 10
    prod1 mat2 20
    prod1 mat3 10
    prod2 mat1 20
    prod2 mat3 30

    I want to query those material which are common for both prodcuts
    say like this
    mat1
    mat3

    I nes to use this in php

    Thanks in advance
  • ronverdonk
    Recognized Expert Specialist
    • Jul 2006
    • 4259

    #2
    This should do it[code=sql]select material from table_name as t1 where material in (select material from table_name as t2 where t1.product != t2.product) group by material;[/code]Ronald

    Comment

    • SSG001
      New Member
      • Oct 2007
      • 110

      #3
      Originally posted by ronverdonk
      This should do it[code=sql]select material from table_name as t1 where material in (select material from table_name as t2 where t1.product != t2.product) group by material;[/code]Ronald
      Hey thanks a lot
      it works

      Comment

      • ronverdonk
        Recognized Expert Specialist
        • Jul 2006
        • 4259

        #4
        Originally posted by SSG001
        Hey thanks a lot
        it works
        Knew it would. Glad to be of help. See you next time.

        Ronald

        Comment

        Working...