Raised This Month: $ Target: $400
 0% 

INT to INT issue in MySQL.


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
plastGNU
Junior Member
Join Date: Jul 2004
Location: Sweden
Old 07-29-2005 , 08:28   INT to INT issue in MySQL.
Reply With Quote #1

Im trying to straight a problem out concerning MySQL and getting info from one table to another using INT in column as on target table and VARCHAR as source column in source table. ( target = table2, source = table1)
Of what i've understood I need to use an INT in the table1 where my VARCHAR column is, as most practical I presume its best to use an `id` int(11) to make this work, by identify itself as a global SELECT depending on ip=192.168.0.1 AND port=27015 like this:
Code:
SELECT `id` FROM servers WHERE ip='192.168.0.1' AND port='27015'
and trough this INT(id) I then can grep info from whichever column in the same table(1) I ever want, depending on ip and port that is.

But now to the problem, how do I tell my plugin to grep the info I want, like I have a column called `longname`, how do I tell my plugin to get the info from column `longname` (depending on ip and port columns) and put that in my INT column in table2.

Like this perhaps: UPDATE `table2` SET my_server=table1.id WHERE table1.id=table1.longname

Im I realy out of bounds or am I close to the solution, but hasnt reliazed it?
Approciate all help I can get.

tia
plastGNU is offline
Brad
AMX Mod X Team Member
Join Date: Jun 2004
Old 07-29-2005 , 10:40  
Reply With Quote #2

To help us understand the situation better, can your post the structure of both tables for us to see?
Brad is offline
plastGNU
Junior Member
Join Date: Jul 2004
Location: Sweden
Old 07-29-2005 , 11:11  
Reply With Quote #3

I will shortly, not at home atm. Will do as soon as I come home.
plastGNU is offline
Johnny got his gun
Veteran Member
Join Date: Jan 2004
Location: Tokyo
Old 07-29-2005 , 12:33  
Reply With Quote #4

I think I got it to work:

Code:
mysql> select * from t2;
+----+------+
| c1 | c2   |
+----+------+
|  1 | NULL |
+----+------+
1 row in set (0.00 sec)

mysql> select * from t1;
+----+------+
| c1 | c2   |
+----+------+
|  1 |    5 |
+----+------+
1 row in set (0.00 sec)

mysql> update t2 set t2.c2 = t1.c2 where t1.c1 = t2.c1;
ERROR 1109: Unknown table 't1' in where clause
mysql> update t2, t1 set t2.c2 = t1.c2 where t1.c1 = t2.c1;
Query OK, 1 row affected (0.05 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> select * from t1;
+----+------+
| c1 | c2   |
+----+------+
|  1 |    5 |
+----+------+
1 row in set (0.00 sec)

mysql> select * from t2;
+----+------+
| c1 | c2   |
+----+------+
|  1 |    5 |
+----+------+
1 row in set (0.00 sec)
The error occurred because I left out table "t1" from the first update line. In the next try I added it with a comma, and it updated the table.
Johnny got his gun is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 14:45.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode