As i know, "Subqueries can assign column values for each record".
example: lets consider this database,
user (id, name, age)
user_detail (user_id[foreign], user_email, address)
Now we can select all email and name by subquery like this:
SELECT id, (SELECT user_email FROM user_detail WHERE user_detail.user_id = user.id LIMIT 1) as email,
name, age
FROM user
WHERE 1
This will the output table like:
_ _ _ _ _ _ _ _ _ _ _ _ _
| id | email | name | age |
+-------------------------+
---------All rows----------
Now how can i query with it laravel eloquent?
More specific ... I have some tables,
1. session (id, name)
2. account (id, name, group)
3. action (id, action_name, detail)
4. another_table (id, detail)
5. transaction (id, from_account_id, to_account_id, session_id,
action_table_id, another_table_id, other_attributes )
now i want a single query to get each line as a object, and hole a array query should return
result (transaction_id, session_name, from_account_name, to_account_name,
action_name, another_table_detail, other_attributes)
and finally send them to json, such that i read them by just a for loop.