Joining to same table to display values next to each other
-
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 thisOwner 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
-
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 thisOwner 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
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[^]
-
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[^]
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