To perform a SELECT query using a RIGHT JOIN in TypeORM, we can use the following syntax:
const result = await getConnection()
.createQueryBuilder()
.select([
'users.id',
'users.name',
'addresses.address'
])
.from(User, 'users')
.rightJoin(Address, 'addresses', 'addresses.userId = users.id')
.where('users.id = :userId', { userId: 1 })
.getRawMany();
In this example, we are selecting the id
, name
, and address
fields from the users
and addresses
tables. We are also performing a right join between the two tables on the userId
field. Finally, we are filtering the results to only return the row with id
equal to 1. The getRawMany()
method returns an array of raw database results.
Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss
Asked: 2023-05-22 18:04:29 +0000
Seen: 7 times
Last updated: May 22 '23
How to extract tables from a website using Beautiful Soup scraping?
What is the most effective approach to establish foreign keys for three adjacent tables?
Why does the parent persist data by inserting instead of updating when using InheritanceType.JOINED?
How can tables with differing columns be combined together through union?
Can a table of contents be automatically created in Google Docs for tables?
What is the problem with hive indexing when dealing with partitioned tables?