Mysql Help

  • juedvaga80
  • Born
  • Born
  • juedvaga80
  • Posts: 3

Post 3+ Months Ago

Hi all I have a question to create a query in mysql
I have a table as follows

--------------------------------------------------
| Id | name | value1 | value2 | value3 | value4 |
--------------------------------------------------
| 1 | A | 12 | null | 14 | null |
| 2 | F | 12 | null | 34 | null |
| 3 | G | 14 | null | 45 | null |
| 4 | T | 23 | null | 65 | null |
| 5 | H | 56 | null | 23 | null |
| 6 | M | 35 | null | 34 | null |

and I would like to make a query that gives me this:

---------------------------------
| Id | name | value1 | value3 |
---------------------------------
| 1 | A | 12 | 14 |
| 2 | F | 12 | 34 |
| 3 | G | 14 | 45 |
| 4 | T | 23 | 65 |
| 5 | H | 56 | 23 |
| 6 | M | 35 | 34 |

and I'm quite lost how to do it, anyone can help please!!

thanks to all

Greetings
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • SpooF
  • ٩๏̯͡๏۶
  • Bronze Member
  • User avatar
  • Posts: 3422
  • Loc: Richland, WA

Post 3+ Months Ago

SQL Code: [ Select ]
SELECT ID, name, value1, value3 FROM your_table
  • juedvaga80
  • Born
  • Born
  • juedvaga80
  • Posts: 3

Post 3+ Months Ago

hola jeje Spoof
well, that was my first choice gif "alt =": P "title =" Razz ">
but of course what happens is that my table is updated dynamically, I mean you can insert new values into a new column "value5" and delete or make null all the elements of "value4" and of course what I'm looking for a query q identify that different data column contains NULL and q are those fields that show you understand?
Well that is my problem and I'm stuck, can someone help me !!!!!!!!!

thanks
  • Bogey
  • Genius
  • Genius
  • Bogey
  • Posts: 8409
  • Loc: USA

Post 3+ Months Ago

So, you want a query that retrieves all columns that doesn't have null on it? And you add or null columns as you wish?

If that's so, then I think that the MySQL Table needs to be redone so that each row would be null or added instead of column.

If not, then I don't see a problem with SpooF's solution.
  • juedvaga80
  • Born
  • Born
  • juedvaga80
  • Posts: 3

Post 3+ Months Ago

what happens is

I have a function (1) with php, which runs within another function to update all columns NOT just some of my board, after the end of this function (1) I will have another function that will do is run a consultation will have to display all the records whose columns contain data, not those with NULL.

to execute my function (1) another update again see the columns may be one where you have already had data or other information before it had NULL updated and placed the new data.

For example: if the first time you use function (1) positioning data for the columns "value1" and "value2"...the second time running the function q (1) update only the columns "value2", "value3" and "value4" placing NULL column "value1"

my problem is to build a query that the first time you pass by function q (1) and finish this, can read my columns have data table -> Bone "value1 "And" value2 "and understands that for the second time to end the function (1) data only exist for the columns ->" value2 "," value3 "and" value4 "

can you help me??
  • Bogey
  • Genius
  • Genius
  • Bogey
  • Posts: 8409
  • Loc: USA

Post 3+ Months Ago

SQL Code: [ Select ]
SELECT * FROM your_table


Then use PHP to print only the values that are not null

PHP Code: [ Select ]
if($sql_results['table'] != null)
{
    // the field is not null
}
  1. if($sql_results['table'] != null)
  2. {
  3.     // the field is not null
  4. }


That's if I understood you correctly. English is not my first language so I have trouble understanding English from others (especially since it isn't written in perfect English).

Post Information

  • Total Posts in this topic: 6 posts
  • Users browsing this forum: No registered users and 63 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.