I am an intern at a company and started learning about psql, I am quite happy with my code so far to get the lines I want, but now I want to get a list (table?) with that Query over 5000 times with a variable that could be a Smallserial ? More information about the database, I need to join two tables, two see if one necessity is given and then I just need the first and last date of a log from a certain thing_id :
(select key, value, table2.created_at
from public.table1 inner join public.table2
on (table1.id = table2.thing_id)
where access_token is not null
and (key = 'thing2')
and thing_id = 0000
order by key, table2.created_at asc
Limit 1)
UNION ALL
(select key, value, table2.created_at
from public.table1 inner join public.table2
on (table1.id = table2.thing_id)
where access_token is not null
and (key = 'thing2')
and thing_id = 0000
order by key, table2.created_at desc
Limit 1)
Now I would like thing_id = 0000 to change between 1-6000, is there a way to perform that with a script maybe? I would prefer to do it in pgAdmin4, but am open to suggestions.
I would really like to have that in one table, so that I can calculate the difference between those two lines for each individual thing_id.
Thank you if you want to help me.
and thing_id between 1 and 6000?thing_iddoes not exist in the database?