user11100279
user11100279

Reputation:

Adding a temporarily comma into a column without updating any tables

I have two tables and have used a simple query:

SELECT * FROM innerb where not exists 
   (select * from wms where barcode = innerb.barcode) and pcode like '%102';

My results come out like this:

enter image description here

I need to add in a comma for all values so it looks like this:

enter image description here

But I don't want to update the table nor create a new table, just to add it in for few seconds.

Any ideas?

Upvotes: 0

Views: 827

Answers (2)

TineO
TineO

Reputation: 1033

SELECT pcode || ',' as pcode
     , brand || ',' as brand
  FROM table

EDIT: Only works on some DBs. Apparently not MYSQL(unless you configure it to work). What does SQL Select symbol || mean? has a list of what works on which DB

Upvotes: 0

Nick
Nick

Reputation: 147146

You could create a view:

CREATE VIEW innerb_comma AS
SELECT CONCAT(Pcode, ',') AS Pcode,
       CONCAT(Brand, ',') AS Brand,
       CONCAT(Pdescription, ',') AS Pdescription,
       CONCAT(Size, ',') AS Size,
       CONCAT(Barcode, ',') AS Barcode
FROM innerb
WHERE NOT EXISTS (SELECT * FROM wms WHERE barcode = innerb.barcode) 
  AND Pcode like '%102';

Then select from that instead:

SELECT * FROM innerb_comma

Demo on dbfiddle

Upvotes: 2

Related Questions