I have an AS-related MySQL question, specifically when combined with HAVING:
This does work (mind the "(250) AS", second line):
SELECT A.uid, A.name, A.height, A.width,
(250) AS squaresize
FROM tx_fach_domain_model_professional A,
tx_fach_domain_model_category B,
tx_fach_professional_category_mm MM
WHERE MM.uid_local = A.uid and
MM.uid_foreign = 2
HAVING squaresize > 20
ORDER BY squaresize LIMIT 0 , 4;
This does NOT work:
SELECT A.uid, A.name, A.height, A.width,
(A.height * A.width) AS squaresize
FROM tx_fach_domain_model_professional A,
tx_fach_domain_model_category B,
tx_fach_professional_category_mm MM
WHERE MM.uid_local = A.uid and
MM.uid_foreign = 2
HAVING squaresize > 20
ORDER BY squaresize LIMIT 0 , 4;
The strange thing is that it doesn't give me any errors but that it simply returns 4 of the very same rows/records, instead of 4 different ones.
Pretty clueless here..
Above is the simplified version of my real problem.. Where I have (200) in my example above, I'm actually trying to measure the distance value between longitude and latitude values:
SELECT A.uid, A.name, A.latitute, A.longitute,
( 6371 * acos ( cos ( radians(52.52000659999999) )
* cos( radians( A.latitute ) ) * cos( radians( A.longitute ) -
radians(13.404953999999975) ) + sin ( radians(52.52000659999999) ) * sin(
radians( A.latitute ) ) ) ) AS distance
FROM tx_fach_domain_model_professional A,
tx_fach_domain_model_category B,
tx_fach_professional_category_mm MM WHERE MM.uid_local = A.uid and
MM.uid_foreign = 2 HAVING distance < 20 ORDER BY distance LIMIT 0 , 4;
Now this works as long as I don't use HAVING distance < 20 ORDER BY distance .. But as soon as I use these, I get the 4 very same results, instead of the expected 4 different results.
But, in my simplified example, I'm having the exact same issue.
[SOLUTION] This is what did the trick and provided the functionallity what I need - as proposed by @AsConfused:
SELECT A.uid, A.name, A.latitute, A.longitute,
( 6371 * acos ( cos ( radians(52.52000659999999) )
* cos( radians( A.latitute ) ) * cos( radians( A.longitute )
radians(13.404953999999975) ) + sin ( radians(52.52000659999999) ) *
sin(radians( A.latitute ) ) ) ) AS distance
FROM tx_fach_domain_model_professional A JOIN
tx_fach_professional_category_mm MM
on MM.uid_local = A.uid and MM.uid_foreign = 2
HAVING distance < 20
ORDER BY distance LIMIT 0 , 4;
Thanks!!!