0

I have an sql statement that will insert a value to the first empty cell (first empty row in column). And if I ran the php script again, then it inserts into the next null cell etc. Problem: I also want to find out the ID of that row, and value of another column in that row. In the Mysql table below, I want a value inserted in the first null of COLUMN A, and also know the id and value in COLUMN B corresponding to that row (ie id=3 and COLUMN B= 11).

My_TABLE   
ID----  COLUMN A ---- COLUMN B  

1-------    6 -----------------        78  
2 ------   7  -----------------       90  
3 ------   NULL-------------      11  
4 ------   NULL-------------      5  
5  ------  NULL ------------     123

The following sql statement in PHP script will make it possible to insert value to the first empty cell in COLUMN A:

UPDATE My_TABLE  
SET COLUMN A = 83  
WHERE COLUMN A IS NULL  
LIMIT 1;

Result will be:

My_TABLE   
ID----  COLUMN A ---- COLUMN B  

1-------    6 -----------------        78  
2 ------   7  -----------------       90  
3 ------   83----------------      11  
4 ------   NULL-------------      5  
5  ------  NULL ------------     123

I also want to have an sql script that will print within PHP (echo) the values of ID and COLUMN B values corresponding to the first COLUMN A null value (ie ID= 3; COLUMN B= 11). How do I do that? Thank you.

Your Common Sense
  • 156,878
  • 40
  • 214
  • 345
user3043277
  • 15
  • 1
  • 5
  • take a look at this answer - http://stackoverflow.com/a/1751282/689579 – Sean Nov 30 '13 at 00:35
  • "*first empty row in column*" does not make any sense. Rows aren't "inside" columns and there is no such thing as the "first row" either in a relational database. –  Dec 01 '13 at 15:57

1 Answers1

0

Just print the result of the following query before the update query:

SELECT ID, COLUMN B FROM My_TABLE
WHERE COLUMN A IS NULL
LIMIT 1;
Sid
  • 480
  • 1
  • 6
  • 19