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 7875335
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T02:57:57+00:00 2026-06-03T02:57:57+00:00

The query below works fine for returning the column names that are null, what

  • 0

The query below works fine for returning the column names that are null, what I am trying to accomplish is have it return to the first column name with a null value. I also have another column named email that has a unique email address for each row. My problem is I cannot figure out the appropriate syntax for doing this. any help is appreciated!

I am also using php5.2 for this.

 SELECT col FROM (SELECT 'GAME0' AS col, GAME0 AS value FROM USERNAME
       UNION ALL SELECT 'GAME1', GAME1 FROM USERNAME
       UNION ALL SELECT 'GAME2', GAME2 FROM USERNAME
       UNION ALL SELECT 'GAME3', GAME3 FROM USERNAME
       UNION ALL SELECT 'GAME4', GAME4 FROM USERNAME
       UNION ALL SELECT 'GAME5', GAME5 FROM USERNAME
       UNION ALL SELECT 'GAME6', GAME6 FROM USERNAME
       UNION ALL SELECT 'GAME7', GAME7 FROM USERNAME
       UNION ALL SELECT 'GAME8', GAME8 FROM USERNAME
       UNION ALL SELECT 'GAME9', GAME9 FROM USERNAME
       UNION ALL SELECT 'GAME10', GAME10 FROM USERNAME
       UNION ALL SELECT 'GAME11', GAME11 FROM USERNAME
       UNION ALL SELECT 'GAME12', GAME12 FROM USERNAME
       UNION ALL SELECT 'GAME13', GAME13 FROM USERNAME
       UNION ALL SELECT 'GAME14', GAME14 FROM USERNAME
       UNION ALL SELECT 'GAME15', GAME15 FROM USERNAME
       UNION ALL SELECT 'GAME16', GAME16 FROM USERNAME
       UNION ALL SELECT 'GAME17', GAME17 FROM USERNAME
       UNION ALL SELECT 'GAME18', GAME18 FROM USERNAME
       UNION ALL SELECT 'GAME19', GAME19 FROM USERNAME
    ) allValues 
    WHERE value is null and email='emailaddress'

EDIT:
if the query above is unneeded, I need something like below, where I can change the value of the first null value. Again syntax is my biggest problem.

update username
SET CASE GAME0
    WHEN GAME0 IS NOT NULL THEN GAME1
    WHEN GAME1 IS NOT NULL THEN GAME2
    WHEN GAME2 IS NOT NULL THEN GAME3
    WHEN GAME3 IS NOT NULL THEN GAME4
    WHEN GAME4 IS NOT NULL THEN GAME5
    WHEN GAME5 IS NOT NULL THEN GAME6
    WHEN GAME7 IS NOT NULL THEN GAME8
    WHEN GAME8 IS NOT NULL THEN GAME9
    WHEN GAME9 IS NOT NULL THEN GAME10
    WHEN GAME10 IS NOT NULL THEN GAME11
    WHEN GAME11 IS NOT NULL THEN GAME12
    WHEN GAME12 IS NOT NULL THEN GAME13
    WHEN GAME13 IS NOT NULL THEN GAME14
    WHEN GAME14 IS NOT NULL THEN GAME15
    WHEN GAME15 IS NOT NULL THEN GAME16
    WHEN GAME16 IS NOT NULL THEN GAME17
    WHEN GAME17 IS NOT NULL THEN GAME18
    WHEN GAME18 IS NOT NULL THEN GAME19
  END where EMAIL='emailaddress'
  • 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-03T02:57:58+00:00Added an answer on June 3, 2026 at 2:57 am

    You can make this query much simplier and do some of the calculations through php:

    $arr_field = array();
    foreach(range(0, 19) as $i)
        $arr_field[] = "GAME{$i}";
    
    $str_add = implode(' + ', $arr_field);
    $str_select = implode(', ', $arr_field);
    
    $query = 
    mysql_query("
        SELECT {$str_select}
        FROM USERNAME
        WHERE ({$str_add}) IS NULL AND email = 'emailaddress'
    ");
    
    // Then get the NULL column through a loop
    
    while($row = mysql_fetch_assoc($query))
        foreach($arr_field as $h)
            if ( ! isset($row[$h])) {
    
                echo "Found column! {$h}<br />";
                break;
    
            }
    

    Baiscly I add all the 20 fields together, and if any of these 20 values are NULL, the result becomes NULL. I fetch all 20 values, then loop through php to find NULL fields.

    To be honest though, I would have made another stucture having a second table handling these GAME0 – GAME19 fields instead.

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

Sidebar

Related Questions

I have written an SQL script having the below query. The query works fine.
I have an INSERT query that works fine, but when I add an extra
I'm using the SQL query box in phpMyAdmin (MyISAM). Below works fine unless I
Below SQL query works when the spaces in the role name are replaced by
I have an SQL query (below) that essentially takes a student from tbStudents, and
I have the query below that when run it says that 325 rows were
I have a query that seems to be returning the wrong data from the
Query below works fine when user selects different dates but when user selects same
I am trying to create a query in MS SQL 2005 that will return
I currently have the code below it works fine up until I actually try

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.