Home >Backend Development >PHP Tutorial >mysql one-to-many query

mysql one-to-many query

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-09-14 09:41:191368browse

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?

Reply content:

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

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn