Hi,
I am trying to order by my result but somehow query is failing. What I am trying to achieve is, I am trying to get all published reviews at a place if no userid is passed but when passed my query becomes a union query but some query is when I try to apply limit and order by clause.Following is my quey.
SELECT reviewCount, place_name,event_id,place_id,description,pin_rate,place_lat,place_long,broadcast,status,created_on,user_id,pictures_url,videos_url,
resourceLocation,_ID,_CAS (
(SELECT (SELECT COUNT(`place_id`) AS `count` FROM `pins` WHERE place_id='MMI000' AND pin_type='review' AND status=1 ) AS reviewCount,p.place_name,
p.event_id,p.place_id,p.description,p.pin_rate,p.place_lat,p.place_long,p.broadcast,p.status,p.created_on,p.user_id,
ARRAY 'https://s3.ap-south-1.amazonaws.com/mmi-uat-exploreimages/pin/event/original/' || v FOR v IN p.pictures END AS pictures_url,
ARRAY 'https://s3.ap-south-1.amazonaws.com/mmi-uat-exploreimages/pin/event/original/' || v FOR v IN p.videos END AS videos_url,
'http://development.mapmyindia.com/explore/api/events/'||META(p).id AS resourceLocation,META(p).id AS _ID, META(p).cas AS _CAS FROM pins p
USE INDEX(`place-review` USING GSI) WHERE p.place_id='MMI000' AND p.pin_type='review' AND p.status=1)
UNION
(SELECT (SELECT COUNT(`place_id`) AS `count` FROM `pins` WHERE place_id='MMI000' AND pin_type='review' AND status=1 ) AS reviewCount,p.place_name,
p.event_id,p.place_id,p.description,p.pin_rate,p.place_lat,p.place_long,p.broadcast,p.status,p.created_on,p.user_id,
ARRAY 'https://s3.ap-south-1.amazonaws.com/mmi-uat-exploreimages/pin/event/original/' || v FOR v IN p.pictures END AS pictures_url,
ARRAY 'https://s3.ap-south-1.amazonaws.com/mmi-uat-exploreimages/pin/event/original/' || v FOR v IN p.videos END AS videos_url,
'http://development.mapmyindia.com/explore/api/events/'||META(p).id AS resourceLocation,META(p).id AS _ID, META(p).cas AS _CAS FROM pins p
USE INDEX(`user_review` USING GSI) WHERE p.user_id='a6a8be4aeb4bf02df817b0ed1e6b276f' AND p.status IS NOT MISSING AND p.place_id='MMI000'
AND p.pin_type='review')
) AS result ORDER BY user_id='a6a8be4aeb4bf02df817b0ed1e6b276f' DESC, pin_create_date DESC LIMIT 10 OFFSET 0