I am working on it Two tables contain records; one is the admin table, which contains all detail, and the second location of shops first I want to check latitude and longitude and get the result from shop_location it works fine, and after that, I want to check the status of a shop which is on and show the result
Here is my MYSQL QUERY, which works fine
SELECT DISTINCT s_number,radious, ( 3959 * ACOS( COS( RADIANS(
latitude ) ) * COS( RADIANS( "33.5967558" ) ) * COS( RADIANS(
"73.3869814" ) - RADIANS( longitude ) ) + SIN( RADIANS( latitude
) ) * SIN( RADIANS("33.5967558" ) ) ) ) AS distance FROM
Shop_Location HAVING distance <= radius/1000 ORDER BY distance
ASC
HERE IS MY SECOND Query
SELECT * from Admins WHERE shopstatus='ON'
Phonenumber in both tables is the same but not unique I want to get the result from shop_location Query and after that check status of a shop (ON) show Result.
I want to solve it with Query.
Assuming that both tables are linked with "s_number" (shop number), you may try the following SQL
SELECT DISTINCT Shop_Location.s_number,radious, ( 3959 * ACOS( COS( RADIANS(
latitude ) ) * COS( RADIANS( "33.5967558" ) ) * COS( RADIANS(
"73.3869814" ) - RADIANS( longitude ) ) + SIN( RADIANS( latitude
) ) * SIN( RADIANS("33.5967558" ) ) ) ) AS distance FROM
Shop_Location, admins where
Shop_Location.s_number=admins.s_number and admins.shopstatus='ON'
HAVING distance <= radius/1000 ORDER BY distance
ASC
maybe like this:
SELECT DISTINCT
Shop_location.s_number,
Shop_location.radious,
(
3959 * ACOS(
COS(RADIANS(latitude)) * COS(RADIANS("33.5967558")) * COS(
RADIANS("73.3869814") - RADIANS(Shop_location.longitude)
) + SIN(
RADIANS(Shop_location.latitude)
) * SIN(RADIANS("33.5967558"))
)
) AS DISTANCE,
Admins.shopstatus
FROM
Shop_Location
LEFT JOIN
Admins
ON
Admins.s_number = Shop_location.s_number
HAVING
DISTANCE <= radius / 1000
ORDER BY
DISTANCE ASC
HERE IS THE RIGHT ANSWER
SELECT DISTINCT
Admins.email,Admins.address,Admins.adminname,
Admins.diliveryfee,Admins.endingtime,Admins.minorder
,Admins.name,Admins.password,Admins.shopimage,
Admins.shopmessage,Admins.phonenumber,
Admins.shopname,Admins.shopstatus FROM (
SELECT Admins.email,Admins.address,Admins.adminname,Admins.diliveryfee,Admins.endingtime,Admins.minorder,Admins.name,Admins.password,Admins.shopimage,Admins.shopmessage,Admins.phonenumber,Admins.shopname,Admins.shopstatus,Shop_Location.radious AS shopLocationRadius, ( 6371 * ACOS( COS(
RADIANS( latitude ) ) * COS( RADIANS( "33.5967558" ) ) *
COS( RADIANS( "73.3869814" ) - RADIANS( longitude ) ) +
SIN( RADIANS( latitude ) ) * SIN(
RADIANS("33.5967558" )
) ) ) AS distance FROM Shop_Location INNER JOIN
Admins ON
(Admins.phonenumber = Shop_Location.s_number) WHERE
Admins.shopstatus='ON' HAVING distance <= radious/1000
ORDER BY distance ASC)
AS Admins
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.