Jump to content

[SOLVED] Active Row?


madhatter301

Recommended Posts

Hi,

 

I have an sql table with various fields in, one of which is "Active" which is an enum 'y' or 'n'. Basically This table holds different events, of which only 1 may be active at one time. So my question is, is their an easier/better way of doing this kind of thing. At the moment I have to check all rows in the table to find which one has active set to 'y', then if i want to change it, set it to 'n' and set the new row i want active to 'y'. Any advice on this would be appreciated.

 

Thanks

Link to comment
Share on other sites

Hello madhatter301,

 

You can select the desired row using the sql query posted by AndyB.

 

For updation:

 

To set the row to 'n' , you have to write two sql query:

 

1.  SELECT id from test WHERE `active` = 'y'

retrieve id_from from above statement

 

2  UPDATE `test` SET `active` = 'n' WHERE id=id_from

 

 

Regards

Aniesh Joseph

Link to comment
Share on other sites

Well in that case I would set the active field to be an int(1) and use 0 for not active and 1 for active. The enum would just be a waste of processing time.

 

If you want when you pull it out of the DB you can (I know this works in Oracle but not sure about MySQL) do this

 

SELECT DECODE(active, 0, 'n', 1, 'y') FROM table ...

 

 

--FrosT

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.