Results 1 to 2 of 2
  1. #1
    Join Date
    Jun 2015
    Posts
    1

    Unanswered: Help with MySQL query

    Hello,

    I have problem with creating query in MySQL for following problem:

    In my table there are six columns, where two records have same values for first three columns, and different for other three:

    Col1 Col2 Col3 Col4 Col5 Col6
    .
    .
    X Y Z aaa bbb ccc
    X Y Z ddd eee fff
    .
    .

    As result I have to get:

    Col1 Col2 Col3 Col4 Col5 Col6 Col7 Col8 Col9
    .
    .
    X Y Z aaa bbb ccc ddd eee fff
    .
    .

    Thank you in advance!

    Regards,

    Marko

  2. #2
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    so thay could be somethign like:-
    Code:
    select a.col1,a.col2,a.col3, a.col4, a.col5, a.col6, b.col4, b.col5, b.col6
      from mytable as A
    join mytable as b
      on (a.col1 = b.col1 and a.col2 = b.col2 and a.col3 = b.col3)
    where
       a.col4 <> b.col4 and a.col5 <> b.col5 and a.col6 <> b.col6
    the join specifies that columns 1,2 & 3 must be the same
    the where specifies that columns 4,5 & 6 must be different
    but you will get two rows for each pairing
    X Y Z aaa bbb ccc ddd eee fff
    and
    X Y Z ddd eee fff aaa bbb ccc
    I'd rather be riding on the Tiger 800 or the Norton

Posting Permissions

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