API with NestJS #90. Using various types of SQL joins
It’s a very common case to need to combine multiple related tables. In SQL, we can do that using a join statement. Therefore, this article explains various types of joins along with real-life examples. Inner joins A few articles ago, we defined the users and posts tables.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
CREATE TABLE users ( id int GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, email text NOT NULL UNIQUE, name text NOT NULL, password text NOT NULL, address_id int UNIQUE REFERENCES addresses(id) ); CREATE TABLE posts ( id int GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, title text NOT NULL, post_content text NOT NULL, author_id int REFERENCES users(id) NOT NULL ); |
It’s typical to retrieve a particular post along […]