Skip to content
Advertisement

SQL – select where for specific id, all distinct values for other column exist

I am having a bit of a hard time explaining the logic I want to achieve in the title.

Anyway, I have a database containing two tables (rent and car).

The car table contains data about cars (license number and such) and currently is:

The rent table contains data about rents went in the rental agency:

I want to query the cid, rno (client_id, request number) that ordered in this specific request cars from all companies available (ford and renault).

I achieved it by creating an array of companies rented for every cid,rno and compared it to an array of all companies available:

returns 55,1,"{Ford,renault}" because client 55 ordered in request 1 a car from ford and renault (12345678, 13371337).

problem is, I am not allowed to use array_agg in class, what is an other way to achieve this functionality?

thanks

Advertisement

Answer

If you want to avoid array aggregation, you could write the query as follows:

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement