Fetching ID's that match multiple rows.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • write2ashokkumar
    New Member
    • Feb 2007
    • 39

    Fetching ID's that match multiple rows.

    hi...

    i have the table like this,

    id --------- name
    --------------------
    1 ---------- xxx
    1 ---------- yyy
    2 ---------- xxx
    3 ---------- xxx
    3 ---------- yyy
    4 ---------- yyy
    5 ---------- zzz

    consider, one id is in more than one name. But,

    I need the output like
    id --------- name
    --------------------
    1 ---------- xxx
    1 ---------- yyy
    3 ---------- xxx
    3 ---------- yyy

    i will search using the field name, i give the search input is xxx and yyy.
    i want the result, which are having the both values.

    Thanks
    S.Ashokkumar.
  • pradeep kaltari
    Recognized Expert New Member
    • May 2007
    • 102

    #2
    Originally posted by write2ashokkuma r
    hi...

    i have the table like this,

    id --------- name
    --------------------
    1 ---------- xxx
    1 ---------- yyy
    2 ---------- xxx
    3 ---------- xxx
    3 ---------- yyy
    4 ---------- yyy
    5 ---------- zzz

    consider, one id is in more than one name. But,

    I need the output like
    id --------- name
    --------------------
    1 ---------- xxx
    1 ---------- yyy
    3 ---------- xxx
    3 ---------- yyy

    i will search using the field name, i give the search input is xxx and yyy.
    i want the result, which are having the both values.

    Thanks
    S.Ashokkumar.
    Hi,
    Try the following query:

    [code=sql]
    SELECT * FROM table x WHERE NAME IN ('xxx','yyy') AND x.ID IN
    (
    SELECT y.ID FROM table y
    WHERE NAME IN ('xxx','yyy') AND x.NAME<>y.NAME
    )
    [/code]

    I hope this solves your problem.

    Regards,
    Pradeep

    Comment

    Working...