Muugii Muugii - 1 month ago 5
MySQL Question

Is there a query way to select a table with multiple items with columns to show but one column to show all from the table

I have a two tables joining to show a list of items and currently it goes something like this.


SELEC tableA.item1, tableA.item2, tableB.item3, tableB.item 4, tableA.item5 FROM tableA INNER JOIN tableB ON tableA.item2 = tableB.item1 WHERE tableA.item1 = A


And shows like this

item1 item2 item3 item4 Item5
A Z 1 0.1 B1
A Y 2 0.2 B2
A X 3 0.3 B3


However I want it to show one column, for example item1, to show all items that are in the tableA. Such as like this

item1 item2 item3 item4 item5
A Z 1 0.1 B1
A Y 2 0.2 B2
A X 3 0.3 B3
W
V
U


Something like this. Is there a way like SELECT *item1, item2 FROM tableA, etc.

Answer

Have you tried Union?

SELEC tableA.item1, tableA.item2, tableB.item3, tableB.item 4, tableA.item5 FROM tableA INNER JOIN tableB ON tableA.item2 = tableB.item1 WHERE tableA.item1 = A
UNION
SELECT NULL as item1, item2, NULL as item3, NULL as item 4, NULL as item5 FROM tableA