David Raymond, on Tuesday, February 12, 2019 03:48 PM, wrote...
>Not sure if this will fix your specific issue, but if you're using a query as
>a single
>value it needs to be in parenthesis, so something like
>
> insert into t (a, b, c, d, e, idate) values ('p006', 1, 2, (SELECT d FROM t
> WHERE a = 'p006'
>AND max(idate)), 4, '2019-02-12');
I get,
sqlite> insert into t (a, b, c, d, e, idate) values ('p001', 1, 2, (SELECT d
FROM t WHERE a = 'p001' AND max(idate)), 4, '2019-02-12');
Error: misuse of aggregate function max()
-----Original Message-----
From: sqlite-users [mailto:sqlite-users-boun...@mailinglists.sqlite.org] On
Behalf Of Jose Isaias Cabrera
Sent: Tuesday, February 12, 2019 3:42 PM
To: James K. Lowden; SQLite mailing list
Subject: Re: [sqlite] Checking differences in tables
>James K. Lowden, on Tuesday, February 12, 2019 11:39 AM, wrote...
>>On Tue, 12 Feb 2019 15:05:29 +0000
>>Jose Isaias Cabrera <jic...@outlook.com> wrote:
>>
>>> >SELECT * From t WHERE datestamp = "20190208"
>>>
>>> Ok, Simon, I'll bite; :-) Imagine this table:
>>>
>>> t (n INTEGER PRIMARY KEY, a, b, c, d, e, idate)
>>
>>That's better.
>>
>>> how would I find the differences in the fields based on the different
>>> idate?
>>
>>select ...
>>from t as now join t as then
>>on now.idate = '20190208'
>>and then.idate = '20190207' -- note single quotes
>>and ... -- other things that match
>>where ... --- things that don't match
>>
>>Can't be more specific than that when the question is "find the
>>differences".
>
>No, this is great. This is great, thanks.
One last question on this... Imagine this scenario...
create table t (n INTEGER PRIMARY KEY, a, b, c, d, e, idate);
insert into t (a, b, c, d, e, idate) values ('p001', 1, 2, 'n', 4,
'2019-02-11');
insert into t (a, b, c, d, e, idate) values ('p002', 2, 2, 'n', 4,
'2019-02-11');
insert into t (a, b, c, d, e, idate) values ('p003', 3, 2, 'n', 4,
'2019-02-11');
insert into t (a, b, c, d, e, idate) values ('p004', 4, 2, 'y', 4,
'2019-02-11');
insert into t (a, b, c, d, e, idate) values ('p005', 5, 2, 'y', 4,
'2019-02-11');
if I am inserting new records into the table, and there is a field, say "d", I
want to keep the last value of that field for the last inserted record, how can
I do this? I am trying this,
insert into t (a, b, c, d, e, idate) values ('p001', 1, 2, SELECT d FROM t
WHERE a = 'p001' AND max(idate), 4, '2019-02-12');
insert into t (a, b, c, d, e, idate) values ('p002', 1, 2, SELECT d FROM t
WHERE a = 'p002' AND max(idate), 4, '2019-02-12');
insert into t (a, b, c, d, e, idate) values ('p003', 1, 2, SELECT d FROM t
WHERE a = 'p003' AND max(idate), 4, '2019-02-12');
insert into t (a, b, c, d, e, idate) values ('p004', 1, 2, SELECT d FROM t
WHERE a = 'p004' AND max(idate), 4, '2019-02-12');
insert into t (a, b, c, d, e, idate) values ('p005', 1, 2, SELECT d FROM t
WHERE a = 'p005' AND max(idate), 4, '2019-02-12');
insert into t (a, b, c, d, e, idate) values ('p006', 1, 2, SELECT d FROM t
WHERE a = 'p006' AND max(idate), 4, '2019-02-12'); -- new
But, of course, it's not working. I get,
Error: near "SELECT": syntax error
Thougths? thanks.
_______________________________________________
sqlite-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
_______________________________________________
sqlite-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
_______________________________________________
sqlite-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users