question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

unknown column in having clause

See original GitHub issue

Issue type:

[ ] question [ ] bug report [ ] feature request [ ] documentation issue

Database system/driver:

[ ] cordova [ ] mongodb [ ] mssql [+ ] mysql / mariadb [ ] oracle [ ] postgres [ ] cockroachdb [ ] sqlite [ ] sqljs [ ] react-native [ ] expo

TypeORM version:

[ ] latest [ ] @next [+ ] 0.2.18 (or put your version here)

Steps to reproduce or a small repository showing the problem:

 const queryBuilder = this.restaurantRepository.createQueryBuilder('brands')
      .addSelect('brands.*, deliveryInfos.*, businessHours.*')
      .addSelect(`( 6371 * acos( cos( radians(${lat}) ) * cos( radians( brands.latitude ) ) * cos( radians( brands.longitude ) - radians(${lng}) ) + sin( radians(${lat}) ) * sin( radians( latitude ) ) ) )`,'distance')
      .leftJoinAndSelect('brands.deliveryInfos','deliveryInfos')
      .leftJoinAndSelect('brands.businessHours','businessHours')
      .where('brands.active=1 AND brands.deleted=0')
      .having('distance < 5')
      .orderBy('brands.created_at')

I got unknown column from this code block. Any suggestion?

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:1
  • Comments:6

github_iconTop GitHub Comments

4reactions
codekeyzcommented, Jan 29, 2020

Any update on this issue? Am having issues with this

0reactions
tigersoftdevcommented, Jan 30, 2021

@sahibhuseyn I think the distance alias you are using for your calculation is by default out of the scope of brands entity and that is causing the issue. I had similar case and when I used .getRawMany() method at the end, the error was gone.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unknown column in 'having clause' - mysql
The SQL standard requires that HAVING must reference only columns in the GROUP BY clause or columns used in aggregate functions.
Read more >
mysql 5.7 - Unknown column in Having Clause
Although the objective has been achieved by using Where Clause before Group By, but this error is still bothering. Any help would be...
Read more >
103961: Error: "Unknown column 'foo' in 'having clause' ...
If the HAVING clause refers to a column that is ambiguous, a warning occurs. In the following statement, col2 is ambiguous because it...
Read more >
MySQL : Unknown column in 'having clause' - YouTube
MySQL : Unknown column in 'having clause ' [ Beautify Your Computer : https://www.hows.tech/p/recommended.html ] MySQL : Unknown column in ...
Read more >
MySQL Operational Error: "Unknown column 'x' in 'having ...
Based on this model, I perform the following query in a MySQL backend. x = 5 expr = Sum(F('f2')) o = Example.objects.using('mysql') q...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found