I have a Grid which returns data for a query so in my case i run 2 querys, the first one will get me the total row count, the other gets me the data and supports the paging / scrolling in the grid.
Below is the first query to get row count in this case its 29
select count(*) as count FROM Contacts AS f WHERE f._type="farm" and f.tract IN [12979,12980,12981,12982,13255,13260,13261] and LOWER(f.PropertyAddress.streetName) = LOWER("Mikro")
The Query below returns the data for grid but has duplicate rows, in this case 58 rows where the first query has only 29
SELECT META(f).id AS DocId,
f.Owners.owner1FName || IFMISSINGORNULL((CASE WHEN (LENGTH(f.Owners.owner1SpouseFName) > 0) THEN " & " || f.Owners.owner1SpouseFName || " " ELSE " " END), " ") || f.Owners.owner1LName AS owner_1,
TRIM(f.Owners.owner2FName || IFMISSINGORNULL((CASE WHEN (LENGTH(f.Owners.owner2SpouseFName) > 0) THEN " & " || f.Owners.owner1SpouseFName || " " ELSE " " END), " ") || f.Owners.owner2LName) AS owner2,
f.Marketing.privacy,
ARRAY { CASE WHEN v.type IS NOT MISSING THEN LOWER(v.type) ELSE "default" END: CASE WHEN LENGTH(v. `number`) = 10 THEN "(" || SUBSTR(v.`number` , 0,3) || ") " || SUBSTR(v.`number` , 3,3) || "-" || SUBSTR(v.`number` , 6,4) ELSE v.`number` END } FOR v IN f.phones END AS phones,
ARRAY {CASE WHEN v.type IS NOT MISSING THEN LOWER(v.type) ELSE "default" END :v.`address`} FOR v IN f.emails END AS emails,
f.Marketing.farm_id,
f.PropertyAddress.houseNumber,
f.PropertyAddress.streetName || IFMISSINGORNULL(" " || f.PropertyAddress.streetType || " ", "") || f.PropertyAddress.streetSuffix AS streetName,
f.PropertyAddress.city,
f.PropertyAddress.state,
f.beds,
f.baths,
f.partialBaths,
f.`pool`,
f.fireplace,
f.ownerOccupied,
f.tract,
t.name AS tract_name,
f.mailingAddress.address || " " || f.mailingAddress.city || " " || f.mailingAddress.state || " " || f.mailingAddress.zip ||"-" || f.mailingAddress.zip4 AS mailing_address
FROM Contacts AS f LEFT
JOIN Contacts AS t ON t._type ="tract_info"
AND ANY b IN t.tract_id SATISFIES b = f.tract END
WHERE f._type="farm"
AND f.PropertyAddress.streetName IS NOT MISSING
AND TONUMBER(f.PropertyAddress.houseNumber) IS NOT MISSING
AND f.tract IN [12979,12980,12981,12982,13255,13260,13261]
AND LOWER(f.PropertyAddress.streetName) = LOWER("Mikro")
ORDER BY f.PropertyAddress.streetName,
TONUMBER(f.PropertyAddress.houseNumber)
LIMIT 100
OFFSET 0
So how can i prevent duplicate rows as in this case