Unexpected behaviour when using groupby in eloquent query for latest recordsGet most recent row with group by and LaravelLaravel 4 Eloquent Query Using WHERE with OR AND OR?How to Create Multiple Where Clause Query Using Laravel Eloquent?Converting a MariaDB-Statement into a Laravel4 Eloquent-QueryOrderBy in Laravel 5How To GroupBy the latest record on the groupLaravel error in query that has “as having”Laravel : Select and GroupBy SQL Query Error. Multiple Selects with groupBy? Is it Possible?Laravel Eloquent group by most recent recordIs there any function to get the last entry in groupby in query builder or eloquent?Raw Query TO Laravel Eloquent

Can I lend a small amount of my own money to a bank at the federal funds rate?

Count the number of triangles

Defending Castle from Zombies

Fantasy Macro Economics: What would Merfolk trade for?

Journal published a paper, ignoring my objections as a referee

Term used to describe a person who predicts future outcomes

In Endgame, wouldn't Stark have remembered Hulk busting out of the stairwell?

What is Soda Fountain Etiquette?

Why does Sauron not permit his followers to use his name?

Why can't I identify major and minor chords?

Why is 3/4 a simple meter while 6/8 is a compound meter?

Is this position a forced win for Black after move 14?

Find feasible point in polynomial time in linear programming

Is there an in-universe explanation given to the senior Imperial Navy Officers as to why Darth Vader serves Emperor Palpatine?

Why is the Grievance Studies affair considered to be research requiring IRB approval?

web scraping images

What should be done with the carbon when using magic to get oxygen from carbon dioxide?

Magnesium's Role in Photosynthesis

Stolen MacBook should I worry about my data?

How do I portray irrational anger in first person?

How did medieval manors handle population growth? Were there room for more fields to be ploughed?

Why did Lucius make a deal out of Buckbeak hurting Draco but not about Draco being turned into a ferret?

Which polygons can be turned inside out by a smooth deformation?

How to prevent a hosting company from accessing a VM's encryption keys?



Unexpected behaviour when using groupby in eloquent query for latest records


Get most recent row with group by and LaravelLaravel 4 Eloquent Query Using WHERE with OR AND OR?How to Create Multiple Where Clause Query Using Laravel Eloquent?Converting a MariaDB-Statement into a Laravel4 Eloquent-QueryOrderBy in Laravel 5How To GroupBy the latest record on the groupLaravel error in query that has “as having”Laravel : Select and GroupBy SQL Query Error. Multiple Selects with groupBy? Is it Possible?Laravel Eloquent group by most recent recordIs there any function to get the last entry in groupby in query builder or eloquent?Raw Query TO Laravel Eloquent






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















I'm trying to get the latest records in a group by query using eloquent in laravel.



My current query is:



 $clubs = ClubsLooking::select('a.*')
->from(DB::raw('(SELECT *, (3959 * acos( cos( radians('.Auth::user()->latitude.') ) *
cos( radians( latitude ) )
* cos( radians( longitude ) - radians('.Auth::user()->longitude.')
) + sin( radians('.Auth::user()->latitude.') ) *
sin( radians( latitude ) ) )
) AS distance FROM clubs_looking ORDER BY created_at DESC) a'))
->groupBy('a.club_id')
->limit(4)
->get();


The query looks complex but is just using the haversine method of calculating distance between two coordinates and returning the result as a column named distance.



I was under the impression that by using this nested query I would be able to group by using the latest created_at date after reading this answer - Get most recent row with group by and Laravel



However when I run this query I always get the oldest record first, I've tried playing around in multiple ways with it but to no avail.



Does anyone with a larger brain than me know what I'm doing wrong?










share|improve this question
























  • Can you screenshot your table structure? :)

    – Benjamin Beganović
    Mar 27 at 21:46

















0















I'm trying to get the latest records in a group by query using eloquent in laravel.



My current query is:



 $clubs = ClubsLooking::select('a.*')
->from(DB::raw('(SELECT *, (3959 * acos( cos( radians('.Auth::user()->latitude.') ) *
cos( radians( latitude ) )
* cos( radians( longitude ) - radians('.Auth::user()->longitude.')
) + sin( radians('.Auth::user()->latitude.') ) *
sin( radians( latitude ) ) )
) AS distance FROM clubs_looking ORDER BY created_at DESC) a'))
->groupBy('a.club_id')
->limit(4)
->get();


The query looks complex but is just using the haversine method of calculating distance between two coordinates and returning the result as a column named distance.



I was under the impression that by using this nested query I would be able to group by using the latest created_at date after reading this answer - Get most recent row with group by and Laravel



However when I run this query I always get the oldest record first, I've tried playing around in multiple ways with it but to no avail.



Does anyone with a larger brain than me know what I'm doing wrong?










share|improve this question
























  • Can you screenshot your table structure? :)

    – Benjamin Beganović
    Mar 27 at 21:46













0












0








0


0






I'm trying to get the latest records in a group by query using eloquent in laravel.



My current query is:



 $clubs = ClubsLooking::select('a.*')
->from(DB::raw('(SELECT *, (3959 * acos( cos( radians('.Auth::user()->latitude.') ) *
cos( radians( latitude ) )
* cos( radians( longitude ) - radians('.Auth::user()->longitude.')
) + sin( radians('.Auth::user()->latitude.') ) *
sin( radians( latitude ) ) )
) AS distance FROM clubs_looking ORDER BY created_at DESC) a'))
->groupBy('a.club_id')
->limit(4)
->get();


The query looks complex but is just using the haversine method of calculating distance between two coordinates and returning the result as a column named distance.



I was under the impression that by using this nested query I would be able to group by using the latest created_at date after reading this answer - Get most recent row with group by and Laravel



However when I run this query I always get the oldest record first, I've tried playing around in multiple ways with it but to no avail.



Does anyone with a larger brain than me know what I'm doing wrong?










share|improve this question














I'm trying to get the latest records in a group by query using eloquent in laravel.



My current query is:



 $clubs = ClubsLooking::select('a.*')
->from(DB::raw('(SELECT *, (3959 * acos( cos( radians('.Auth::user()->latitude.') ) *
cos( radians( latitude ) )
* cos( radians( longitude ) - radians('.Auth::user()->longitude.')
) + sin( radians('.Auth::user()->latitude.') ) *
sin( radians( latitude ) ) )
) AS distance FROM clubs_looking ORDER BY created_at DESC) a'))
->groupBy('a.club_id')
->limit(4)
->get();


The query looks complex but is just using the haversine method of calculating distance between two coordinates and returning the result as a column named distance.



I was under the impression that by using this nested query I would be able to group by using the latest created_at date after reading this answer - Get most recent row with group by and Laravel



However when I run this query I always get the oldest record first, I've tried playing around in multiple ways with it but to no avail.



Does anyone with a larger brain than me know what I'm doing wrong?







laravel eloquent






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 27 at 21:03









RockhopperRockhopper

981 silver badge10 bronze badges




981 silver badge10 bronze badges















  • Can you screenshot your table structure? :)

    – Benjamin Beganović
    Mar 27 at 21:46

















  • Can you screenshot your table structure? :)

    – Benjamin Beganović
    Mar 27 at 21:46
















Can you screenshot your table structure? :)

– Benjamin Beganović
Mar 27 at 21:46





Can you screenshot your table structure? :)

– Benjamin Beganović
Mar 27 at 21:46












0






active

oldest

votes










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55386416%2funexpected-behaviour-when-using-groupby-in-eloquent-query-for-latest-records%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes




Is this question similar to what you get asked at work? Learn more about asking and sharing private information with your coworkers using Stack Overflow for Teams.







Is this question similar to what you get asked at work? Learn more about asking and sharing private information with your coworkers using Stack Overflow for Teams.



















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55386416%2funexpected-behaviour-when-using-groupby-in-eloquent-query-for-latest-records%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현