Update with Select Query

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
phppick
Forum Commoner
Posts: 57
Joined: Thu Aug 14, 2003 5:59 am

Update with Select Query

Post by phppick »

I have Two tables in my POSTGRES DATABASE,

1. Student
2. Library_Student_Info

I want to Join the two tables and Update the 'Library_Student_Info' table with matched records. I am using the following Query

UPDATE Library_Student_Info SET Name = (
SELECT Name
FROM Student WHERE Student_ID= Library_Student_Info.Student_ID
LIMIT 1);



Anybody Can Help me ???

And also this i tried but Error..

UPDATE Library_Student_Info EM SET Name = (SELECT Name FROM Student DIR WHERE
DIR.Student_ID = EM.Student_ID AND
EM.Student_ID IS NOT NULL)
User avatar
scorphus
Forum Regular
Posts: 589
Joined: Fri May 09, 2003 11:53 pm
Location: Belo Horizonte, Brazil
Contact:

Post by scorphus »

A WHERE clause should be missing:

Code: Select all

UPDATE Library_Student_Info SET Name = (
SELECT Name
FROM Student WHERE Student_ID= Library_Student_Info.Student_ID
LIMIT 1) WHERE Name = '_null' OR <something>;
What is the error message returned by Postgre?

Scorphus.
Post Reply