Today, another Mysql Data Query problem occurs in the project. Simply put, when you want to process a query (multiple records may be returned), you can use
Limit to solve some problems.
Eg:
Select a. *, (select B. ID from table_ B B where...) as T1 from table_a
If: (select B. ID from table_ B B where ......) multiple results are returned, an error occurs. (Can I splice the returned results into a string in T1? What about parsing rules at the front end? Have thought about this problem
. However, limit can also be used to meet this requirement .)
The solution is as follows:
Select TT .*
, (Select S. name from tbl_rel_route_has_destination RHD, tbl_obj_scene s where RHD. sceneid = S. ID and RHD. routeid = (select sp. routeid from tbl_obj_sale_plan SP where sp. id = TT. planid) limit 1) as DES1
, (Select S. name from tbl_rel_route_has_destination RHD, tbl_obj_scene s where RHD. sceneid = S. ID and RHD. routeid = (select sp. routeid from tbl_obj_sale_plan SP where sp. id = TT. planid) limit 1, 1) as des2
From tbl_obj_travel_team TT
Where TT. cityid = (select gov. cityid from tbl_obj_government Gov, tbl_obj_user u where u. governmentid = gov. ID and U. ID = 1)
If limit 2nd, that is, the data entries in the query result do not exist, null is returned, and the frontend determines the result)
Limit usage:
First parameter: Start offset (0 ).
Second parameter: Limit the number of records to be queried.
Note:
1. If there is only one parameter. Eg: limit 10 returns the first 10 results. Limit N is equivalent to limit 0, n
2. Two parameters, for example: limit 10, 10, return 11-20.
3. to retrieve all record rows from an offset to the end of the record set, you can specify the second parameter
-1. limit 10,-1