![]() |
MySQL Update / Join on match
I keep getting stuck trying to figure this one out. I have two tables. One is a list of articles, the other is a list of users.
articles table: userid, name, articletitle, articletext, postdate users table: userid, name The articles table is fully populated except for the name column. So I need to update / join the articles table - name column, with the users table - name column, where the userid from both match. I've tried to find an example online, but they all use the standard t.1 or t.2 generic descriptions for the columns and I can't wrap my head around it without seeing better descriptors prudent to my exact situation (like "name" and "userid" in the example). Like I swear it's (SELECT * FROM table1 as t1 INNER JOIN table2 as t2 ON t2.t1_id = t1.t2_id) or something as I've used it in the past. But when I wrote it down in my notes I didn't provide better descriptors. :Oh crap :helpme:helpme |
select a.articletitle, a.articletext, a.postdate, b.name from articletable as a, usertable as b where a.userid = b.userid
|
are you trying to SELECT or UPDATE?
|
what is primary key in your tables? userid should be your primary key. try to join on that.
and why using as try after from select * from table 1 inner join table 2 on t1.userid=t2.userid or this will work i think select * from table 1 where userid = (select userid from table2); |
got it using:
UPDATE table_1 AS t1, table_2 AS t2 SET t1.name = t2.name WHERE t1.userid = t2.userid |
upgrade... yes... i didn`t get you in first...
|
All times are GMT -7. The time now is 05:28 PM. |
Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc