Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9156071
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:42:17+00:00 2026-06-17T12:42:17+00:00

this is my first question ever, so please be patient.. :) We are two

  • 0

this is my first question ever, so please be patient.. 🙂

We are two developers and both have the same MySql DB with same tables and values.

One is MySql version 5.5 and works ok (apparently) as I am told by the other developer.

On my machine with MySql 5.1.44 (a basic MAMP install) I have the following weird problem.

A very huge query (not mine) fails with error "Column ‘xd’ cannot be null".

Removing pieces I slimmedi it down to this:

select xd, avg(media) from questionario_punteggi where somefield = 1 union select 1,2

Note, there is no record with somefield = 1 so the first select returns an empty set

We have a SELECT with AVG() function that returns an empty set UNION another SELECT that returns something (1,2 are just random values I put now as an example)

  • If I remove the AVG() the query works.
  • If I remove xd (and the 2 of 1,2 to the right) the query works.
  • If I remove the UNION the query works.
  • If I set some record with somefield = 1 the query works.
  • On the other machine 5.5 the query works.

Otherwise the error is:

1048 – Column ‘xd’ cannot be null

Fields are:

`xd` char(3) NOT NULL DEFAULT '001',
`media` decimal(7,4) NOT NULL DEFAULT '0.0000',
`somefield` tinyint(4) NOT NULL DEFAULT '0',

Gosh. Any help? Thanks.

UPDATE

It has been reported to me as a BUG in MySql <= 5.1 that was fixed before MySql 5.5. I don’t have the details but I trust the source

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T12:42:18+00:00Added an answer on June 17, 2026 at 12:42 pm

    try using the SELECT IFNULL();

    SELECT IFNULL(xd,0), avg(media) 
    FROM questionario_punteggi 
    WHERE somefield = 1 
    UNION
    SELECT 1,2
    

    http://dev.mysql.com/doc/refman/5.0/en/control-flow-functions.html#function_ifnull

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is my first ever question on SO. So I have a MYSQL table
My first ever question here. Please excuse me, I have just entered into C++
Hi guys this is my first question ever on SO so please go easy
Here's my HTML. Apologies for formatting - this is my first-ever question! <div id=Template>
This is my first question, so please be gentle. I'm trying out Apache Camel
this is my first question I have searched for any launching activity questions and
This is literally the first thing I've ever written in C, so please feel
this is my first ever question. I am developing a iPad app that allows
this is actually my first question ever in this awesome site. I usually find
this is my first question posted on the internet ever, I was usually able

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.