Jump to content

simple question

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
2 replies to this topic

#1
happy

happy

    Newbie

  • Members
  • PipPip
  • 25 posts
I had 6 rows in a table. i added a 7th row. in my 2nd column i have ids 1-8 each id spanning 10 rows. In the new column i want to add text that corrospands into the correct cells.

example
 trackid | artistid | albumid |                 track_name                  | video_stream | video_download | artist_name
---------+----------+---------+---------------------------------------------+--------------+----------------+-------------
 1001001 |        1 |    1001 | You make me smile                           | f            | f              |
 1001002 |        1 |    1001 | She's my ride home                          | f            | f              |
 1001003 |        1 |    1001 | Into the ocean                              | f            | f              |
 1001004 |        1 |    1001 | What if we could                            | f            | f              |
 1001005 |        1 |    1001 | Hate me                                     | t            | t              |
 1001006 |        1 |    1001 | Congratulations                             | f            | f              |
 1001007 |        1 |    1001 | Overweight                                  | f            | f              |
 1001008 |        1 |    1001 | Let it go                                   | f            | f              |


the table doesnt match up. but the tables continues to have artist id 2 then 3, 4 etc.


if i wanted to add 'blue october' where artistid is 1 i thought it was this.

INSERT INTO tracks (artist_name) VALUES ('Blue October') WHERE artistid=1;

this isnt working. what is the correct syntax to add data into only one column across specific rows.

Edited by WingedPanther, 06 May 2009 - 07:19 AM.
a


#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
You need something like:
INSERT INTO tracks (artistid, albumid, track_name, video_stream, video_download) VALUES (1,1001,'Blue October','f','f');

You cannot use a WHERE clause as part of an INSERT statement unless you have a subselect.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#3
Orjan

Orjan

    Writes binary right handed and hex left handed

  • Moderators
  • 3,298 posts
to achieve what you want, you need to do an UPDATE:

UPDATE tracks SET artist_name = 'Blue October' WHERE artistid=1;

On the other hand, as you have an Artist ID, I suggest you set up an artist table containing the ids and names, and eventual other info about the artists, that's how you usually divide into multiple tables.
__________________________________________
I study Information Systems at Karlstad University when I'm not on CodeCall