将数据插入第一个空列单元格而不创建新行

将数据插入第一个空列单元格而不创建新行

问题描述:

I want to add data to a table, one column at a time. Therefore I don't want to always add a new row, as the column I'm adding to may not have much data in compared to the other columns. As a result I suppose I want to add the data to the first empty cell in the specified column without necessarily adding a new row to the whole table (as there may already be enough rows).

My table has 5 columns.

I'm currently using:

$sql=("INSERT INTO [MY_TABLE] ([MY_COLUMN]) VALUES ('[MY_DATA]')");

Please could someone assist with the correct code? I know it's basic stuff but I'm new to mySQL.

Thanks in advance.

我想将数据添加到表中,一次一列。 因此,我不想总是添加新行,因为我添加的列可能与其他列相比没有太多数据。 因此,我想我想将数据添加到指定列中的第一个空单元格,而不必向整个表添加新行(因为可能已经有足够的行)。 p>

我的表有5列。 p>

我目前正在使用: p>

  $ sql =(“INSERT INTO [MY_TABLE]([  MY_COLUMN])VALUES('[MY_DATA]')“); 
  code>  pre> 
 
 

有人可以协助使用正确的代码吗? 我知道这是基本的东西,但我是mySQL的新手。 p>

提前致谢。 p> div>

So you can use UPDATE statement with a WHERE condition to target that specific row

UPDATE table_name SET column_name = 'whatever' WHERE column_name = '' AND id = '1'

If you want to update all rows where that column is blank than simply use

UPDATE table_name SET column_name = 'whatever' WHERE column_name = ''

no need of using id in above query

Reference on UPDATE