Results 1 to 3 of 3

Thread: pairs of data

  1. #1
    Join Date
    Jan 2009
    Posts
    8

    Unanswered: pairs of data

    hello!

    How can I display if the query results more than one value?
    For example, how can I do a query that produces all pairs of salespeople who are living in the same city.


    Thanks in advance.

  2. #2
    Join Date
    Jan 2004
    Location
    Croatia, Europe
    Posts
    4,094
    Provided Answers: 4
    Honestly, I don't understand the question. Could you provide sample input and desired output to illustrate the problem?

  3. #3
    Join Date
    Sep 2002
    Location
    UK
    Posts
    5,171
    Provided Answers: 1
    Are you saying that if the following salespeople exist:
    Code:
    City   Salesperson
    ----   -----------
    London Fred
    London Shiela
    London James
    then the SQL should show all possible pairs for London? i.e.
    Code:
    SP1    SP2
    ---    ---
    Fred   Shiela
    Fred   James
    James  Shiela
    If so then this would do it:
    Code:
    select sp1.name, sp2.name
    from salesperson sp1
    join salesperson sp2 on sp2.city = sp1.city
    where sp1.name < sp2.name;
    If I used != instead of < then you would get 6 results instead of 3, with both "Fred Shiela" and "Shiela Fred" in the results for example.

Posting Permissions

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