MySQL Update statement:

Keep it clean but fun.
Post Reply
bogezie
Posts: 11
Joined: Mon Aug 05, 2013 10:31 pm

MySQL Update statement:

Post 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.
User avatar
hallsofvallhalla
Site Admin
Posts: 12026
Joined: Wed Apr 22, 2009 11:29 pm

Re: MySQL Update statement:

Post 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;
bogezie
Posts: 11
Joined: Mon Aug 05, 2013 10:31 pm

Re: MySQL Update statement:

Post 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.
bogezie
Posts: 11
Joined: Mon Aug 05, 2013 10:31 pm

Re: MySQL Update statement:

Post 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
User avatar
hallsofvallhalla
Site Admin
Posts: 12026
Joined: Wed Apr 22, 2009 11:29 pm

Re: MySQL Update statement:

Post 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
Post Reply

Return to “Off-Topic”