A problem occurred in the project over the past two days. An error is reported after mysql LIMIT is used.
This is the requirement. I have three tables: infor info table, mconfig material configuration table, and maaply material application form. The requirement is to read who applies for the materials in the application form.
First, write:
SELECT infor. name, infor. phone, infor. add,
Mconfig. mname, mapply. acount, from_unixtime (mapply. atime, '% Y-% m-% D') as 'atime'
FROM mapply right JOIN infor ON mapply. uid = infor. uid inner JOIN mconfig ON mapply. mid = mconfig. mid
WHERE mapply. aid
IN (
SELECT aid
FROM 'mapply' where state = $ state
Order by 'atime ', 'uid' DESC
LIMIT 0, 10
) Www.jbxue.com
An error is returned.
At that time, I did not pay attention to the reported error. I only saw the LIMIT error, so I modified the following code:
SELECT infor. name, infor. phone, infor. add,
Mconfig. mname, mapply. acount, from_unixtime (mapply. atime, '% Y-% m-% D') as 'atime'
FROM mapply right JOIN infor ON mapply. uid = infor. uid inner JOIN mconfig ON mapply. mid = mconfig. mid
WHERE mapply. aid
IN (
SELECT aid
FROM 'mapply' where state = $ state
Order by 'atime ', 'uid' DESC
)
<Pre name = "code" class = "SQL"> LIMIT 0, 10 </pre>
In this case, no error is reported. Mo Li thought it was OK, but after running it, the data was faulty.
Unlike reading the content of the application form, I found that the LIMIT location was wrong. So I sent the LIMIT to IN again. The result is as follows:
This version of MySQL doesn't yet support 'limit & IN/ALL/ANY/SOME subquery'
You can see it IN detail. IN does not support LIMIT. What should we do? Www.jbxue.com
Then du Niang learned that she would use a temporary table IN the IN statement to find out the required content first,
After modification:
SELECT infor. name, infor. phone, infor. add,
Mconfig. mname, mapply. acount, from_unixtime (mapply. atime, '% Y-% m-% D') as 'atime'
FROM mapply right JOIN infor ON mapply. uid = infor. uid inner JOIN mconfig ON mapply. mid = mconfig. mid
WHERE mapply. aid
IN (
SELECT aid
FROM (SELECT 'aid 'FROM 'mapply' where state = $ state
Order by 'atime ', 'uid' DESC
LIMIT) AS 'tp'
)
After running, the problem is solved!