Skip to content
Advertisement

How to pulls related values in PostgreSQL?

Here is my problem.

I have two tables like user and customer. Users can be related to some customer(s).

For example, I have a user who relates to two customers, and the other user relates to three customers, etc.

This is my code that creating tables and inserting values;

I want to pull the user name(s) that relates to customers that id is 1 and 2.

Here is my select code;

But this query demonstrates nothing.

The other select code ;

This query shows like this;

What I want to do is a Select – As – From with the following fields

Advertisement

Answer

One of the possible solution is to use arrays:

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