Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8409395
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T23:53:54+00:00 2026-06-09T23:53:54+00:00

So I am running into a problem with getting the right data from my

  • 0

So I am running into a problem with getting the right data from my query.

I have the following table (Person):

Name  |       xpath        |   value
Derek |  /body/torso/arm   |   left
Derek |  /body/torso/arm   |   right
Derek |  /body/torso/neck  |   Head
Ron   |  /body/torso/neck  |   Head
Ron   |  /body/torso/arm   |   left

So basically the query results i was trying to get were to show the differences (whats missing between the two people).

results:
Name1 |       xpath1       |   value1   | Name2  |   xpath2         |   value2
Derek |  /body/torso/arm   |   right    | Ron    |    NULL          |   NULL

I would even be fine with getting the following back as well

results:
Name1 |       xpath1       |   value1   | Name2  |   xpath2         |   value2
Derek |  /body/torso/arm   |   right    | Ron    |    NULL          |   NULL
Derek |  /body/torso/arm   |   left     | Ron    | /body/torso/arm  |   left  
Derek |  /body/torso/neck  |   Head     | Ron    | /body/torso/neck |   Head    

The query i was using was:

SELECT P.Name , P.xpath, P.value, P1.Name, P2.xpath, P3.value
FROM Person as P
LEFT OUTER JOIN
    Person as P2 ON P.xpath = P2.xpath
WHERE
         P.Name = "Derek"
    AND  P2.Name = "Ron"

The results I keep getting no matter what i try is basically the overlapping data but never what i am actually looking for, seems I am missing something simple or just plainly doing it wrong. Any suggestions? Ultimately i am going to run this in a SPROC but it would be nice to be able to handle multiple names not just 2, but if i had, Derek,Ron,John,Dawn, etc..

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T23:53:56+00:00Added an answer on June 9, 2026 at 11:53 pm

    Give this a shot:

    SELECT    a.Name  AS Name1,
              a.xpath AS xpath1,
              a.value AS value1,
              'Ron'   AS Name2,
              b.xpath AS xpath2,
              b.value AS value2
    FROM      Person a
    LEFT JOIN Person b ON b.Name = 'Ron'
                      AND a.xpath = b.xpath 
                      AND a.value = b.value
    WHERE     a.Name = 'Derek' AND
              b.Name IS NULL
    

    SQLFiddle Demo


    If you wanted to compare Derek to multiple names, you can do a CROSS JOIN of all names to compare to (so that the names can appear in the result set), and LEFT JOIN the same table using xpath, value, and also the names specified in the CROSS JOIN:

    SELECT     a.Name  AS Name1,
               a.xpath AS xpath1,
               a.value AS value1,
               b.Name  AS Name2,
               c.xpath AS xpath2,
               c.value AS value2
    FROM       Person a
    CROSS JOIN (
               SELECT 'Ron' AS Name UNION ALL
               SELECT 'John'        UNION ALL
               SELECT 'Charles'     UNION ALL
               SELECT 'Aaron'
               ) b
    LEFT JOIN  Person c ON b.Name  = c.Name 
                       AND a.xpath = c.xpath
                       AND a.value = c.value
    WHERE      a.Name = 'Derek' AND
               c.Name IS NULL
    

    SQLFiddle Demo


    And if you wanted to have multiple names on the left side of the comparison (not just “Derek”), just change

    a.Name = 'Derek'
    

    to

    a.Name <> b.Name
    

    in the above query.


    SQLFiddle Demo


    EDIT: Just to take it even further:

    Compare all names to all names:

    SELECT     a.Name  AS Name1,
               a.xpath AS xpath1,
               a.value AS value1,
               b.Name  AS Name2,
               c.xpath AS xpath2,
               c.value AS value2
    FROM       Person a
    CROSS JOIN (SELECT DISTINCT Name FROM Person) b
    LEFT JOIN  Person c ON b.Name  = c.Name 
                       AND a.xpath = c.xpath
                       AND a.value = c.value
    WHERE      a.Name <> b.Name AND 
               c.Name IS NULL
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Running into a problem. I have a table defined to hold the values of
I'm running into a problem inserting rows from a file with 13,000 rows into
I'm running into a problem when trying to select records from my 2005 MS-SQL
I am running into a problem that just doesn't seem right. I've got a
I'm running into the problem of users being able to submit data with '
I'm running into this problem when trying to call a SOAP Web Service from
I have a problem getting the following scenario to work. A student can take
i'm running into a strange problem in Microsoft SQL Server 2008. I have a
I'm running into a problem when trying to create an ArrayList in Java, but
My company is running into a problem with a web service that is written

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.