Last row in table
I have a mysql database. Lets say it has a table called maintable with primary key as main_id. I want to add other tables to the database and use main_id as foriegn keys in those tables. If I want to start with the last row of the maintable how can I using a perl script get main_id from the last row of the maintable. Note that maintable and the new added tables will keep growing in size. Please help me with this mysql query. Thanks. - Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail [EMAIL PROTECTED] To unsubscribe, e-mail [EMAIL PROTECTED] Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php
Jon Frisby---MySQL help needed
Hi Jon, Whatever you have suggested so far hasn't worked. I thought that maybe something is missing in my stating the problem and implementing your suggested solutions. So here is a more expanded picture of the queries: $sth=$dbh-prepare(INSERT INTO TABLE1 (id,var1,var2) VALUES (?,?,?)); $sth-execute(,$var1,$var2); $sth=$dbh-prepare(SELECT \@t1id:=LAST_INSERT_ID()); $sth-execute(); $sth=$dbh-prepare(INSERT INTO TABLE1A (Aid,id,var1) VALUES (?, @t1id, $var1); $sth-execute(,,$var1); Please take a note that in the last prepare statement I have also tried \@t1id ,\@t1id, LAST_INSERT_ID(). I have used these in 'execute' statement too with question marks (?) in the prepare statement. Any new idea please? Thanks, Aamer Try: $sth-execute(...); Sorry for the confusion. Of course I tried the above statement. I took it granted that we would mean the above when we say the following: execute(, \@t1id, $var1...); I still get the same result. I hope you don't quit on me. Thanks. Hrm... Ah! If your code is doing a prepare on a statement of the form: INSERT INTO x VALUES(@t1id, ...) Then you don't need to give @t1id as a parameter in the execute statement... You should only need to provide params to execute for each ? that appears in the INSERT statement... -JF sql, query - Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail [EMAIL PROTECTED] To unsubscribe, e-mail [EMAIL PROTECTED] Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php
Primary and Foreign Keys in MySQL
Hello, I am working on MySQL database. I have come across a 'problem' but don't know how to get around that. The problem is the following: I have a table, say TABLE1, with primary key being called as table1_id. Now there are other tables, like TABLE1A, TABLE1B, TABLE1C etc.. where I want to use primary key of TABLE1 (i.e table1_id) as foreign key. I see a problem in using the function LAST_INSERT_ID(). Lets say I use it to insert a record in TABLE1A, that will work fine. But now if I use it to put a record in TABLE1B it would give me the primary key ID of TABLE1A rather than TABLE1. Please help me out on this. Aamer - Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail [EMAIL PROTECTED] To unsubscribe, e-mail [EMAIL PROTECTED] Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php