Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

118
Views
Select fields from different tables - TypeORM

I am somewhat new to SQL. I have three tables users_table, products_table, and users_orders. The users_table holds basic information about the user and the users_orders table holds information about the user's orders. Here is a structure of the products_table and users_orders.

N.B

Users can signup and create products to be sold on the platform (like a marketplace).

Product table

id: Int
productName: String
price: Int
...
createdBy: Foreign key to user's table

Users orders table

id: Int
isOrdered: bool // to know if a user ordered a particular item
userId: Foreign key to the user's table
productId: Foreign key to the product table

Problem

In the front-end, I make an API call to grab all products from the database and display them on the main page. I want to be able to know if a user has ordered a particular item, if they have, then based on a boolean check, I can make the order button unclickable. This is to prevent them from ordering a particular item twice. (Business requirements).

Expected Behaviour

I currently use TypeORM to handle my database interaction with Postgres. How do I run the query to get all orders from the products_table alongside users_orders to know which item a user has ordered, so that I have the isOrdered field returned back to me?

API Response Example

When I make a call to the DB to get all products, a response like so is returned.

[
 {
  productName: String
  price: Int
  createdBy: User who created the product listing
  date: Date
 }
]

I want to be able to make a single query that can check the users_orders and products_table to know which product the current loggedIn user has made. So the response could be like this

[
 {
  id: Int
  productName: String
  price: Int
  createdBy: User who created it
  isOrdered: Boolean
  productId: Product object details
 }
]

How do I achieve this with TypeORM? Thank you in advance!

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!