I have tried to run a SQL command but I am receiving this error:
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')
The SQL statement is
SELECT * ,
Match(product.title) against (query) + match(product.description) against (query1) +match(product.keyword) against (query2)+match(product.url) against (query2) + (average(review.rating)/100*count(productid))+(100/price)+(site.domainauthority/25)+(10-
CASE
WHEN lcase(seller.city) = lcase(city) THEN TRUNCATE(( 6371 * acos( cos( radians( 23 ) ) * cos( radians( seller.latitude ) ) * cos( radians( seller.longitude ) - radians(24) ) + sin( radians( 24 ) ) * sin( radians( seller.latitude ) ) ) ),1))
ELSE + 0
END AS score
FROM product,
productimages,
review,
seller,
site
WHERE distance < 10
AND productimage.id=product.id
AND product.sellerid =seller.id
AND product.siteid-site.id
AND productmeta.id = product.id
AND review.productid = product.id
AND ((
seller.deliverabletype = "international")
OR (
seller.deliverabletype = "country"
AND seller.country = 'country')
OR (
seller.deliverabletype = "state"
AND seller.country = 'country')
OR
OR (
seller.deliverabletype = "city"
AND seller.country = 'city'))
GROUP BY product.id mysql sql-server
The query was not well formed. One of the closing parenthesis should be at the end.
try this.
TRUNCATE(
( 6371 * acos(
cos( radians( 23 ) ) * cos( radians( seller.latitude ) ) *
cos( radians( seller.longitude ) - radians(24) ) +
sin( radians( 24 ) ) * sin( radians( seller.latitude ) )
)
),1)
ELSE + 0
END) AS score
Related
I have my pagination query I am passing page and size ass ?page=0&size=5. But not getting any result. This is my query.
#Query(
value = "SELECT *,
( 6371 * acos(
cos( radians(:lat) )
* cos( radians( latitude ) )
* cos( radians( longitude )
- radians(:lng) )
+ sin( radians(:lat) )
* sin( radians( latitude ) ) )
) AS distance
FROM stores
WHERE deleted = '0'
HAVING distance < 20000
ORDER BY distance ?#{#pageable}",
countQuery = "select count(*) from stores where deleted = 0",
nativeQuery = true)
public Page<Stores> getAllNearbyStores(
#Param("lat") double lat,
#Param("lng") double lng,
Pageable pageable
);
Error : You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use
near
'_binary'¬í\0sr\0+org.springframework.data.domain.PageRequestÀùPÅÀÇ&\0'
at line 1
there need to add \n-- #pageable\n instead of ?#{#pageable}
Query:
#Query(
value = "SELECT *,
( 6371 * acos(
cos( radians(:lat) )
* cos( radians( latitude ) )
* cos( radians( longitude )
- radians(:lng) )
+ sin( radians(:lat) )
* sin( radians( latitude ) ) )
) AS distance
FROM stores
WHERE deleted = '0'
HAVING distance < 20000
ORDER BY distance \n-- #pageable\n",
countQuery = "select count(*) from stores where deleted = 0",
nativeQuery = true)
public Page<Stores> getAllNearbyStores(
#Param("lat") double lat,
#Param("lng") double lng,
Pageable pageable
);
you can get details here
#Query(
value = "SELECT *,
( 6371 * acos(
cos( radians(:lat) )
* cos( radians( latitude ) )
* cos( radians( longitude )
- radians(:lng) )
+ sin( radians(:lat) )
* sin( radians( latitude ) ) )
) AS distance
FROM stores
WHERE deleted = '0'
HAVING distance < 20000
ORDER BY distance \n-- #pageable\n",
countQuery = "select count(*) from stores where deleted = 0",
nativeQuery = true)
public Page<Stores> getAllNearbyStores(
#Param("lat") double lat,
#Param("lng") double lng,
#PageableDefault(size = 5) Pageable pageable
);
There need to add default size to **#PageableDefault(size = 5). This solved the issue.
I have created a filter where users can find locations within a selected number of miles of a specific point,
My code is the following, I keep getting SQL syntax error near the "left join"
Not sure what the error is, if anyone could help that would be ace, or just point me in the right direction!
SELECT b.*, host,
(6371 *
acos(
cos( radians( '51.514294' ) ) *
cos( radians( `latitude` ) ) *
cos(
radians( `longitude` ) - radians( '-0.042857' )
) +
sin(radians('51.514294')) *
sin(radians(`latitude`))
)
) `distance`
FROM brunches b HAVING
`distance` < $range
LEFT JOIN hosts ON hosts.id = b.hostid
You have an having clause in wrong place (the having clause must not placed between from and join)
SELECT b.*, host,
(6371 *
acos(
cos( radians( '51.514294' ) ) *
cos( radians( `latitude` ) ) *
cos(
radians( `longitude` ) - radians( '-0.042857' )
) +
sin(radians('51.514294')) *
sin(radians(`latitude`))
)
) `distance`
FROM brunches b
LEFT JOIN hosts ON hosts.id = b.hostid
HAVING `distance` < $range
QUERY:
model.client.query("SELECT ( 6371 * acos( cos( radians(:latitude) ) * cos( radians( latitude ) ) * cos( radians(longitude ) - radians(:longitude) ) + sin( radians(:latitude) ) * sin( radians( latitude) ) ) ) AS distance FROM offers where isActive= :isActive ",{'latitude': latitude, 'longitude': longitude,'isActive':1},function (err,rows) {
console.log(err);
});
ERROR
{ Error: ER_PARSE_ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ':latitude) ) * cos( radians( latitude ) ) * cos( radians(longitude ) - radians(:' at line 1
model.client.query("SELECT ( 6371 * acos( cos( radians(?) ) * cos( radians( latitude ) ) * cos( radians(longitude ) - radians(?) ) + sin( radians(?) ) * sin( radians( latitude) ) ) ) AS distance FROM offers where isActive= ? ",[latitude,longitude,latitude,isActive],function (err,rows) {
console.log(err);
});
I can't for the life of me see what is going wrong here. Its most likely something stupid, but I'm blind to it currently! I have a query:
SELECT
Links.Title,
(6371 * acos( cos( radians(43.4347229) ) * cos( radians( Links.Latitude ) ) * cos( radians( Links.Longitude ) - radians(6.737222195) ) + sin( radians(43.4347229) ) * sin( radians( Links.Latitude ) ) ) AS distance
FROM CatLinks,Links WHERE CatLinks.LinkID = Links.ID AND (Links.ID IN (16650,17190,153344) AND Links.isValidated = 'Yes' AND Links.PropertyType IN (1,2,3) AND Links.priceSort <= '9999' AND Links.PropertyType IN (1,2,3) AND Links.priceSort < '9999') ORDER BY distance LIMIT 0,50
..to which I get an error:
Error: Could not execute query: Failed to execute query: 'SELECT
Links.Title, (6371 * acos( cos( radians(43.4347229) ) * cos( radians(
Links.Latitude ) ) * cos( radians( Links.Longitude ) -
radians(6.737222195) ) + sin( radians(43.4347229) ) * sin( radians(
Links.Latitude ) ) ) AS distance FROM CatLinks,Links WHERE
CatLinks.LinkID = Links.ID AND (Links.ID IN (16650,17190,153344))
ORDER BY distance LIMIT 0,50': You have an error in your SQL syntax;
check the manual that corresponds to your MySQL server version for the
right syntax to use near 'AS distance FROM CatLinks,Links WHERE
CatLinks.LinkID =' at line 3
Even trimming it down to a much simpler query, doesn't want to work:
SELECT
glinks_Links.Title,
(6371 * acos( cos( radians(43.4347229) ) * cos( radians( glinks_Links.Latitude ) ) * cos( radians( glinks_Links.Longitude ) - radians(6.737222195) ) + sin( radians(43.4347229) ) * sin( radians( glinks_Links.Latitude ) ) ) AS distance
FROM glinks_CatLinks,glinks_Links ORDER BY distance LIMIT 0,50
I've been going round and round with this issue all morning, so any advice would be much appreciate!
You forgot to close a bracket (near sin( radians( Links.Latitude ) ) ) )). Try this
SELECT
Links.Title,
(
6371 * acos(
cos(radians(43.4347229)) * cos(radians(Links.Latitude)) * cos(
radians(Links.Longitude) - radians(6.737222195)
) + sin(radians(43.4347229)) * sin(radians(Links.Latitude))
)
) AS distance
FROM
CatLinks,
Links
WHERE
CatLinks.LinkID = Links.ID
AND (
Links.ID IN (16650, 17190, 153344)
AND Links.isValidated = 'Yes'
AND Links.PropertyType IN (1, 2, 3)
AND Links.priceSort <= '9999'
AND Links.PropertyType IN (1, 2, 3)
AND Links.priceSort < '9999'
)
ORDER BY
distance
LIMIT 0,50
I'm trying to do this query:
SELECT *, ( 6371 * acos( cos( radians(43.656906) ) * cos( radians( latitude ) ) * cos( radians( longitude ) - radians(-79.434356) ) + sin( radians(43.656906) ) * sin( radians( latitude ) ) ) ) AS distance FROM Locations HAVING distance < 10 AND HAVING category='%Family%'
But I get this error:
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use
near 'HAVING category='%Family%' LIMIT 0, 30' at line 1
Does anybody know what is the problem?
I hope category is column in your table
SELECT *, ( 6371 * acos( cos( radians(43.656906) ) * cos( radians( latitude ) ) * cos( radians( longitude ) - radians(-79.434356) ) + sin( radians(43.656906) ) * sin( radians( latitude ) ) ) ) AS distance FROM Locations where category like '%Family%' HAVING distance < 10
You can not add having conditions twice .You can use "AND" inside the "Having" condition.So the code will be :
SELECT *, ( 6371 * acos( cos( radians(43.656906) ) * cos( radians( latitude ) ) * cos( radians( longitude ) - radians(-79.434356) ) + sin( radians(43.656906) ) * sin( radians( latitude ) ) ) ) AS distance FROM Locations HAVING distance < 10 AND category='%Family%'
You need to remove the second HAVING and just use AND to tell MySQL that both conditions must hold.
SELECT *, ( 6371 * acos( cos( radians(43.656906) ) * cos( radians( latitude ) ) * cos( radians( longitude ) - radians(-79.434356) ) + sin( radians(43.656906) ) * sin( radians( latitude ) ) ) ) AS distance FROM Locations HAVING distance < 10 AND category='%Family%'