Welcome to dbFreaks.com!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

update table select

 
   Database Help (Home) -> PHP SQL RSS
Next:  06135  
Author Message
Bob Bedford

External


Since: Mar 09, 2008
Posts: 38



(Msg. 1) Posted: Wed Aug 06, 2008 4:08 pm
Post subject: update table select
Archived from groups: alt>php>sql (more info?)

Hi all,

I've a table in with I've a field called "year".

Now this is not what we want anymore but instead we want a value defining
the "period":

table period
1 before 1914
2 between 1914 and 1918
3 between 1919 and 1945
4 from 1946

for now I've those values in the table I want to update:
id; year; period (default 0)
1; 1950; 0
2; 1987; 0
....

how to upgrade the period column using the year value ?

update mytable set period = (select if(year < 1914),1, if(year between 1914
and 1918),2,if(year between 1919 and 1945),3,4)

unfortunately it doesn't work and all example mon mysql.com are on testing
values, not real values from databases.

Thanks for helping.

Bob

 >> Stay informed about: update table select 
Back to top
Login to vote
Captain Paralytic

External


Since: Jan 14, 2008
Posts: 245



(Msg. 2) Posted: Wed Aug 06, 2008 4:08 pm
Post subject: Re: update table select [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

On 6 Aug, 15:08, "Bob Bedford" wrote:
> Hi all,
>
> I've a table in with I've a field called "year".
>
> Now this is not what we want anymore but instead we want a value defining
> the "period":
>
> table period
> 1   before 1914
> 2   between 1914 and 1918
> 3   between 1919 and 1945
> 4   from 1946
>
> for now I've those values in the table I want to update:
> id; year; period (default 0)
> 1; 1950; 0
> 2; 1987; 0
> ...
>
> how to upgrade the period column using the year value ?
>
> update mytable set period = (select if(year < 1914),1, if(year between 1914
> and 1918),2,if(year between 1919 and 1945),3,4)
>
> unfortunately it doesn't work and all example mon mysql.com are on testing
> values, not real values from databases.
>
> Thanks for helping.
>
> Bob

Please do NOT multi post. Cross post if you must bit do NOT multi
post. It just wastes people's time. See: http://www.blakjak.demon.co.uk/mul_crss.htm

I have already posted a follow up to your post in
comp.databases.mysql.

 >> Stay informed about: update table select 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
Text search table with reference to another table - Hi Guys, I'm using MATCH to perform a text search of two fields in a table, below: SELECT *, MATCH(name, description) AGAINST ('$item' IN BOOLEAN MODE) AS score FROM items WHERE type = '2' AND MATCH(name, description) AGAINST ('$item' IN BOOLEAN MODE)...

Many To Many Table: self join maybe, but how? - Trying here too. A simple many to many table named, say, foo looks like: +------+------+ | id | it | +------+------+ | 60 | 4 | | 60 | 6 | | 60 | 9 | | 61 | 4 | | 61 | 6 | | 61 | 8 | | 62 | 4 | | 62 | 6 | | 6...

NULL fields in table - efficiency question - I have read it is better to always have all the fields in a table set to NOT NULL as this makes it much quicker. In one case I have a table where all fields qualify for this accept for one which is comments. This will only sometimes be filled. Am I....

Backing up from one table to another and adding date/time .. - I want to insert the data from one record in one table into another table in a mysql database, adding the current date and time to a field in the table the data is going into. Thus when a record is changed, I am backing it up and indicating the date and...

PHPtriad v2.2.1 removal - When I fist started using apache/php/mysql I used phptriad [a wonderful piece of kit] to get me up and running. I've used this ever since. I'm think inow of 'upgrading' to laters versions of all three applications, and have found various tutorials/Ho...
   Database Help (Home) -> PHP SQL All times are: Pacific Time (US & Canada)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]