0

Say I have a table t

Table name: t
key : c1

|----+----+----|
| c1 | c2 | c3 |
|----+----+----|
|  1 | A  | $  |
|  2 | B  | *  |
|  3 | C  | ^  |
|----+----+----|

I need to select two rows from the table and show them side by side like this:

| 1 | 2 |
| A | B |
| $ | * |

For smaller tables like this, I could concat each values and show like this:

SELECT concat (t1.c1, " | ", t2.c1),
       concat (t1.c2, " | ", t2.c2),
       concat (t1.c3, " | ", t2.c3)
FROM t AS t1,
     t AS t2
WHERE t1.c1 = 1
  AND t2.c1 = 2;

Not sure how to go about large tables with many columns since I have to give name of each column explicitly.

Pretty helpful for me if I need to compare two rows and see where they differ. Showing them as rows itself is one way but, my table row won't fit inside screen width.

Vivek
  • 448
  • 2
  • 11

0 Answers0