SQL insert where
deicist
Manchester, UK
Hi guys, I'm trying to teach myself SQL & PHP and it's going quite well. The only problem I have now is that my current table has a field called 'release_name' which I've been sorting my selection statement by. This release name consists of dates in the form d-m-yy. Unfortunately this is obviously a pain to sort by so I want to add a datestamp field with the format yyyymmdd and then sort my selection by that. Now, I can alter my table to add this field but I already have a lot of data in there so I want to select a group of rows that have a release_name (eg: 1-8-06) and then populate the datestamp field for that selection with the correct date (20060801). How do I go about doing this? I'm thinking it's something along the lines of:
insert into tablename (datestamp) Values (20060801) where (release_name = '1-8-06')
is that right or am I on the wrong track completely?
edit: nevermind, worked it out. For future reference the correct statement is:
update tablename set datestamp='20060801' where release_name='1-8-06';
insert into tablename (datestamp) Values (20060801) where (release_name = '1-8-06')
is that right or am I on the wrong track completely?
edit: nevermind, worked it out. For future reference the correct statement is:
update tablename set datestamp='20060801' where release_name='1-8-06';
0
Comments
SELECT DISTINCT release_name FROM (select * from TABLENAME order by datestamp DESC) as test;