I currently have the following SQL query.
SELECT quote.id,
lines.id
FROM Quote quote
INNER JOIN Quote_Line as lines
ON quote.id = lines.quote_id
FOR JSON AUTO
As expected it correctly returns the following JSON:
[
{
"id": 1,
"lines": [
{
"id": 1
}
]
}
]
Now i am trying to extend this output with another 1-to-1 JOIN (Quote to Quote_Customer). How do i write this JOIN to get the following output:
[
{
"id": 1,
"customer": {
"id": 1
},
"lines": [
{
"id": 1
}
]
}
]
I have tried adding a simple LEFT JOIN Quote_Customer customer ON quote.id = customer.quote_id
, but this adds a nested customer
object inside every lines
-object.
Any ideas?
2条答案
按热度按时间hxzsmxv21#
One method would be to use a correlated subquery in the
SELECT
:nkoocmlb2#
try to run below query
you can get below output: