table A :suit
table B :suit_goods
Association conditions: suit.suit_id = suit_goods.suit_id
Corresponding relationship: A => Multiple B
SQL select How to achieve the above result? ? ? Ask God for enlightenment
Result:
When a record is associated with the suit_goods table, first this record is retained, and other associated data is displayed below
phpcn_u15822017-06-22 11:56:37
select ...
from suit s
right join suit_goods g on s.suit_id = g.suit_id
大家讲道理2017-06-22 11:56:37
Looking at you, suit_goods should be used as the main table
select ...
from suit_goods g
left join suit s on s.suit_id = g.suit_id
天蓬老师2017-06-22 11:56:37
SELECT
`B`.*,
`A`.`name`
FROM
`suit_goods` `B`
LEFT JOIN
`suit` `A`
ON
`A`.`suit_id` = `B`.`suit_id`;
In this way, the data is basically the same as suit_goods, and an additional column of suit.name (this is written casually because I didn’t see the structure of your database) represents the name of the suit to which this good belongs. According to this, the field can be Play freely.