Page 1 of 1

MySQL Update statement:

Posted: Mon Aug 12, 2013 5:44 pm
by bogezie
Hello all,

I'am trying to figure out how to execute a MySQL statement that will Update WHERE min(item) and Available='yes' ... any suggestions?

Item is a column and and Available is a column too.

I want to update this particular row at the minimum item number and where Available is no.

Re: MySQL Update statement:

Posted: Mon Aug 12, 2013 5:55 pm
by hallsofvallhalla
I may not be reading the post right but whats wrong with

Code: Select all

SELECT MIN(Item) FROM table_name where Available = 'no';
And if that doesnt work then

Code: Select all

SELECT Item FROM table_name where Available = 'no' ORDER BY Item ASC LIMIT 1;

Re: MySQL Update statement:

Posted: Mon Aug 12, 2013 6:15 pm
by bogezie
The SELECT function i wrote works it is:

SELECT min(items) FROM `bogogame`.`itembox` WHERE Available='Yes'

And this works, it displays the minimum item that is available, but i want to UPDATE where the min(item) is Available.

Re: MySQL Update statement:

Posted: Mon Aug 12, 2013 6:19 pm
by bogezie
I guess what im trying to say is that I want to UPDATE my table (itembox) WHERE the min(item)= *(whatever the lowest item is)* and WHERE Available = Yes

Re: MySQL Update statement:

Posted: Mon Aug 12, 2013 8:04 pm
by hallsofvallhalla
ahhhh

something like

Code: Select all

update `bogogame`.`itembox`  SET Item='Whatever' Where item=(select min(item) from `bogogame`.`itembox`) AND Available = 'Yes')
Should work