Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Inserting data... 2

Status
Not open for further replies.

perlone

Programmer
May 20, 2001
438
US
Hello,


I have a table like this:

[uid] [username] [news]
105 Jorge No news News.
55 Tom No news News.


I want to insert a new news called "Hello" where the userid is 105. How do I do this? For example, I want to add the text "Hello" to the
column "news" where the userid is 105. Please help if you can. Thanks.

The results should be like this:

[uid] [username] [news]
105 Jorge No news News.
Hello
55 Tom No news News. There is no Knowledge that is not power.
Age: 16
E-mail: projectnet01@yahoo.com
School: Coral Springs High (Company:(not done yet) :)
Status: Currently working with C++ for game developing. And making a musical band.
-Aaron
 
This SQL query should work
UPDATE table SET news='Hello' WHERE UID=105 //Daniel
 
thank you. There is no Knowledge that is not power.
Age: 16
E-mail: projectnet01@yahoo.com
School: Coral Springs High (Company:(not done yet) :)
Status: Currently working with C++ for game developing. And making a musical band.
-Aaron
 
the only problem is that it's replacing the previous data. I don't want to replace the old data with a new one. I want to add it along with
the old one. There is no Knowledge that is not power.
Age: 16
E-mail: projectnet01@yahoo.com
School: Coral Springs High (Company:(not done yet) :)
Status: Currently working with C++ for game developing. And making a musical band.
-Aaron
 
You cannot have two values for a given row column pair... you could have an associate table that will have the users id and then values for the other column.. ie:

Users
[uid] [username]
105 Jorge
55 Tom

then another table:
UserNews
[uid] [news]
105 No news News.
105 hello
55 No news News.

Then you would need to query like:

Select Users.username,
UserNews.news
from Users
inner join UserNews
on UserNews.uid = Users.uid
order by Users.username;

To see the results:

username news
Jorge No news News.
Jorge Hello
Tom No news News.

I'm not exactly sure what problem you are trying to solve here, but if what you are asking is exactly what you want, this is one solution.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top