Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2011
    Posts
    7

    Unanswered: Trouble getting result

    I am trying to get distinct city, state where the city name is the same, but the state is different. But I am getting the results twice, just reversed in the columns. Any help to fix this would be greatly appreciated. The following is my query:

    SELECT DISTINCT s1.shipcity ||', '|| s1.shipstate AS CITY_STATE_1, s2.shipcity ||', '|| s2.shipstate AS CITY_STATE_2
    FROM shipment s1, shipment s2
    WHERE (s1.shipcity = s2.shipcity)
    AND (s1.shipstate != s2.shipstate);

    Result of query:

    CITY_STATE_1 CITY_STATE_2
    ------------------------ ------------------------
    Asheville, ND___________Asheville, NC
    Scranton, PA___________Scranton, ND
    Auburn, AL_____________Auburn, ME
    Franklin, NH____________Franklin, KY
    Asheville, NC___________Asheville, ND
    Columbus, GA__________Columbus, IN
    Franklin, KY____________Franklin, NH
    Columbus, IN___________Columbus, GA
    Scranton, ND___________Scranton, PA
    Auburn, ME_____________Auburn, AL

    10 rows selected.
    Last edited by jmax; 10-13-11 at 18:23. Reason: Fix spacing

  2. #2
    Join Date
    Aug 2003
    Location
    Where the Surf Meets the Turf @Del Mar, CA
    Posts
    7,776
    Provided Answers: 1
    SELECT DISTINCT s1.shipcity ||', '|| s1.shipstate AS CITY_STATE_1, s2.shipcity ||', '|| s2.shipstate AS CITY_STATE_2
    FROM shipment s1, shipment s2
    WHERE (s1.shipcity = s2.shipcity)
    AND (s1.shipstate != s2.shipstate)
    AND S1.shipstate > S2.shipsate;
    You can lead some folks to knowledge, but you can not make them think.
    The average person thinks he's above average!
    For most folks, they don't know, what they don't know.
    Good judgement comes from experience. Experience comes from bad judgement.

  3. #3
    Join Date
    Oct 2011
    Posts
    7
    Thank You! Did that, but did not use all three and statements.

Posting Permissions

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