SELECT list is not in GROUP BY clause and contains nonaggregated column .... incompatible with sql_mode=only_full_group_by

Cover Image for SELECT list is not in GROUP BY clause and contains nonaggregated column .... incompatible with sql_mode=only_full_group_by
Matheus Mello
Matheus Mello
published a few days ago. updated a few hours ago

šŸ‘‹ Hey there! Are you struggling with the "Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column" error in MySQL? We've got you covered! šŸ˜Ž

šŸ“ In this blog post, we will address this common issue and provide you with easy solutions to fix it. So, let's jump right into it! šŸš€

šŸ’” The error you encountered usually occurs when you have the sql_mode set to only_full_group_by in your MySQL configuration. This mode requires that all columns in the SELECT list, other than the ones being aggregated (e.g., using functions like COUNT, SUM, etc.), are included in the GROUP BY clause.

šŸ”Ž In your specific query, you're selecting all columns (*) from the tbl_customer_pod_uploads table, grouping them by proof_type. However, the error is thrown because some columns in your SELECT list (e.g., id) are not included in the GROUP BY clause, and they are not functionally dependent on the grouped column.

šŸ› ļø To resolve this issue, you have a few options:

1ļøāƒ£ Include all non-aggregated columns in the GROUP BY clause:

SELECT *
FROM `tbl_customer_pod_uploads`
WHERE `load_id` = '78' AND `status` = 'Active'
GROUP BY `proof_type`, `id`, `user_id`, `load_id`, `bill_id`, `latitude`, `longitude`, `document_type`, `file_name`, `is_private`, `status`, `createdon`, `updatedon`

2ļøāƒ£ Use aggregate functions for non-grouped columns:

SELECT MAX(`id`) AS `id`, MAX(`user_id`) AS `user_id`, MAX(`load_id`) AS `load_id`, MAX(`bill_id`) AS `bill_id`, `proof_type` -- and so on
FROM `tbl_customer_pod_uploads`
WHERE `load_id` = '78' AND `status` = 'Active'
GROUP BY `proof_type`

3ļøāƒ£ Disable only_full_group_by mode (not recommended): Depending on your environment and requirements, you can disable the only_full_group_by mode in your MySQL configuration. However, this is not recommended as it can hide potential errors in your queries.

āš”ļø With these solutions, you should now be able to run your query without encountering the error.

šŸ“¢ If you're looking for even more in-depth explanations and examples, be sure to check out our blog post on this topic. And hey, if you found this information helpful, don't forget to share it with your fellow developers! Sharing is caring, remember? šŸ¤—

šŸ’¬ We would love to hear about your experience with this error and if our solutions worked for you! Leave us a comment below or reach out to us on social media.

Happy coding! šŸ’»šŸŽ‰


More Stories

Cover Image for How can I echo a newline in a batch file?

How can I echo a newline in a batch file?

updated a few hours ago
batch-filenewlinewindows

šŸ”„ šŸ’» šŸ†’ Title: "Getting a Fresh Start: How to Echo a Newline in a Batch File" Introduction: Hey there, tech enthusiasts! Have you ever found yourself in a sticky situation with your batch file output? We've got your back! In this exciting blog post, we

Matheus Mello
Matheus Mello
Cover Image for How do I run Redis on Windows?

How do I run Redis on Windows?

updated a few hours ago
rediswindows

# Running Redis on Windows: Easy Solutions for Redis Enthusiasts! šŸš€ Redis is a powerful and popular in-memory data structure store that offers blazing-fast performance and versatility. However, if you're a Windows user, you might have stumbled upon the c

Matheus Mello
Matheus Mello
Cover Image for Best way to strip punctuation from a string

Best way to strip punctuation from a string

updated a few hours ago
punctuationpythonstring

# The Art of Stripping Punctuation: Simplifying Your Strings šŸ’„āœ‚ļø Are you tired of dealing with pesky punctuation marks that cause chaos in your strings? Have no fear, for we have a solution that will strip those buggers away and leave your texts clean an

Matheus Mello
Matheus Mello
Cover Image for Purge or recreate a Ruby on Rails database

Purge or recreate a Ruby on Rails database

updated a few hours ago
rakeruby-on-railsruby-on-rails-3

# Purge or Recreate a Ruby on Rails Database: A Simple Guide šŸš€ So, you have a Ruby on Rails database that's full of data, and you're now considering deleting everything and starting from scratch. Should you purge the database or recreate it? šŸ¤” Well, my

Matheus Mello
Matheus Mello