laravel
<code>$houses = DB::table('houses')->join('status', 'houses.status_id', '=', 'status.id')->get()</code>
status_id field in the
houses
table, and the corresponding name
field in the status
table needs to be queried;
And what we get in $houses
is the name
field in the status
table. How to change the name to the status_name
name?
This is currently the case: houses
There is no name
field in the table, so there is nothing wrong when checking the status
name name,
You can directly take out the name field from the status
table, but what to do if the houses
table also has a name
field.
Because the title
field is built in the houses
table. If you add a name
field to the houses
table and check it in the join status
table, an error will occur!
laravel
<code>$houses = DB::table('houses')->join('status', 'houses.status_id', '=', 'status.id')->get()</code>
status_id field in the
houses
table, and the corresponding name
field in the status
table needs to be queried;
And what we get in $houses
is the name
field in the status
table. How to change the name to the status_name
name?
This is currently the case: houses
There is no name
field in the table, so there is nothing wrong when checking the status
name name,
You can directly take out the name field from the status
table, but what should be done if the houses
table also has a name
field.
Because the title
field is built in the houses
table. If you add a name
field to the houses
table and check it in the join status
table, an error will occur!
<code>DB::table('houses')->select('*','name as status_name')->join('status', 'houses.status_id', '=', 'status.id')->get();</code>
<code class="sql">DB::table('houses')->select('name as status_name')->join('status', 'houses.status_id', '=', 'status.id')->get()</code>
As keyword, you can give it an alias