Search code examples
sqloracle-databaseoutput-formatting

Get rid from one column duplicate values in two column select


So, I`ve got two columns t1.NAME and t2.ITEMS, for each neme there can be more than one item assigned to it, so I want to select it like:

| NAME | ITEMS |
  JOHN    1
          2
  BEN     4
          7
          3
  DAVE    5

P.s. if it helps, they are connected by t1.id = t2.names_id


Solution

  • Result of my below query is very close to what you want.. the only difference is, there is no blank name, because you cannot directly do that result in one step query.. each item belong to name of each id in t1. BUT you can do some trick there if you want to get the exact result, you can use UPDATE to do some trick with the result.

        SELECT t1.NAME, t2.ITEMS
        FROM t1 INNER JOIN t2 ON t1.id = t2.names_id