Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sqlite EXCEPT and ALTER TABLE

Tags:

sqlite

I have 2 tables with same structure. these 2 tables are monthly snapshots: table1=january table2=february

As i want to compare rows added and removed, i use EXCEPT twice: to get rows added:

select * from table1 
EXCEPT
select * from table2

to get rows removed:

select * from table2 
EXCEPT
select * from table1

in two cases i want to ADD COLUMN the results table with Month/Add-Remove stamp and then UNION those two resulting tables.

i don't how to make it using sqlitebrowser. Could anybody help me? thx

like image 958
Monsieurxu Avatar asked Sep 18 '26 04:09

Monsieurxu


1 Answers

To add a column to the result of a query, just add it to the SELECT clause. To prevent it from affecting the EXCEPT, move the EXCEPT into a subquery:

SELECT *, 'added'
FROM (select * from table1
      EXCEPT
      select * from table2)
UNION ALL
SELECT *, 'removed'
FROM (select * from table2
      EXCEPT
      select * from table1);
like image 108
CL. Avatar answered Sep 22 '26 09:09

CL.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!