SQL insert where

deicistdeicist Manchester, UK
edited August 2006 in Internet & Media
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';

Comments

  • ShortyShorty Manchester, UK Icrontian
    edited August 2006
    Beat me to it!
  • deicistdeicist Manchester, UK
    edited August 2006
    oh, and in case anyone else (in the FUTURE!!) is working on a similar SQL problem, you're probably going to want to know how to sort by the datestamp field, but only show the unique instances of the release_name field (in my case I'm populating a drop down box with the release names, but want them in date order) Anyway, you'll be wanting:

    SELECT DISTINCT release_name FROM (select * from TABLENAME order by datestamp DESC) as test;
Sign In or Register to comment.