Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Joining to same table to display values next to each other

Joining to same table to display values next to each other

Scheduled Pinned Locked Moved Database
help
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Support123
    wrote on last edited by
    #1

    Hi all, I am trying to select values from a table to display them next to each other instead of underneath each other. Here is my attempt: SELECT A.Owner, A.Amount, B.Amount FROM Payment_History A JOIN Payment_History B ON A.Owner = B.Owner AND A.Number <> B.Number WHERE A.Owner = 49622 I have been google-ing it for a while now but so far this is my best attempt. The problem however is that the return twice (there are only two record for this member but some might have up to 15) like this: Owner Amount Amount 49622 11585.678 23143.57 49622 23143.57 11585.678 Please help my get the values to look like this Owner Amount Amount 49622 11585.678 23143.57 Only once like this... Thank you in advance...

    "Many of life's failures are people who did not realize how close they were to success when they gave up." Thomas A. Edison

    W 1 Reply Last reply
    0
    • S Support123

      Hi all, I am trying to select values from a table to display them next to each other instead of underneath each other. Here is my attempt: SELECT A.Owner, A.Amount, B.Amount FROM Payment_History A JOIN Payment_History B ON A.Owner = B.Owner AND A.Number <> B.Number WHERE A.Owner = 49622 I have been google-ing it for a while now but so far this is my best attempt. The problem however is that the return twice (there are only two record for this member but some might have up to 15) like this: Owner Amount Amount 49622 11585.678 23143.57 49622 23143.57 11585.678 Please help my get the values to look like this Owner Amount Amount 49622 11585.678 23143.57 Only once like this... Thank you in advance...

      "Many of life's failures are people who did not realize how close they were to success when they gave up." Thomas A. Edison

      W Offline
      W Offline
      Wendelius
      wrote on last edited by
      #2

      Since in your query you have no joining between the tables, you'll get cartesian product. If I understood you correctly, you want 15 columns, but a single row if owner has 15 rows. If this is correct, have a look at PIVOT[^] queries.

      The need to optimize rises from a bad design. My articles[^]

      S 1 Reply Last reply
      0
      • W Wendelius

        Since in your query you have no joining between the tables, you'll get cartesian product. If I understood you correctly, you want 15 columns, but a single row if owner has 15 rows. If this is correct, have a look at PIVOT[^] queries.

        The need to optimize rises from a bad design. My articles[^]

        S Offline
        S Offline
        Support123
        wrote on last edited by
        #3

        thank you... i will look into it.

        "Many of life's failures are people who did not realize how close they were to success when they gave up." Thomas A. Edison

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups