Home >Backend Development >PHP Tutorial >mysql one-to-many query
Table 1 has a field called ksort with values 1, 2, and 3. These three values correspond to the ID of each piece of data in Table 2. Table 2 has N pieces of data. How can I find three worth of data in ksort?
Table 1 has a field called ksort with values 1, 2, and 3. These three values correspond to the ID of each piece of data in Table 2. Table 2 has N pieces of data. How can I find three worth of data in ksort?
select tb2.* FROM tb1 LEFT JOIN tb2 ON find_in_set(tb2.id,tb1.ksort)
selct * from table 2 where id in ( select ksort from table 1)
I don’t understand what you are asking. That's roughly it?
Either you insert the first three values into a redundant field in the table.
Or do it twice, first find out the value of the ksort field, sort it, and then check it based on the first three, without joining