471,075 Members | 1,284 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,075 software developers and data experts.

Best way to find Primary ID..

If I insert a value into a table what is the best way to find the Primary Field Value..

+--------------+---------------------+------+-----+
| Field | Type | Null | Key |
+--------------+---------------------+------+-----+
| EXTRA_ID | smallint(6) | | PRI |
| DATE_ADDED | datetime | YES | |
| DATE_AMENDED | datetime | YES | |
| NAME | char(30) | | |
| URL | char(30) | | |
| DESCRIPTION | char(250) | | |
| ACTIVE | char(1) | | |
| ISLAND_ID | tinyint(3) unsigned | | |
| resort_id | smallint(6) | | |
| priority | tinyint(1) | | |
+--------------+---------------------+------+-----+

If I insert the value "123" in the name field then a new row is added to the table, with a value in the EXTRA_ID field..

what is best ways of finding the value of the EXTRA_ID field, at the moment I do

select extra_id from {table} where name="123";

but the issue I have got now is I have the names the same in different rows

any ideas ?

Graham

Jul 19 '05 #1
2 1928
If Extra_ID is an autonumber field that is increased whenever a new row is added, then you can use the "Select Last_Insert_ID()" Function.

Just look it up in the docs, it's all there on how to use it.

Brandon
"Graham Mattingley" <gr****@technocom.com> wrote in message news:bn*******************@news.demon.co.uk...
If I insert a value into a table what is the best way to find the Primary Field Value..

+--------------+---------------------+------+-----+
| Field | Type | Null | Key |
+--------------+---------------------+------+-----+
| EXTRA_ID | smallint(6) | | PRI |
| DATE_ADDED | datetime | YES | |
| DATE_AMENDED | datetime | YES | |
| NAME | char(30) | | |
| URL | char(30) | | |
| DESCRIPTION | char(250) | | |
| ACTIVE | char(1) | | |
| ISLAND_ID | tinyint(3) unsigned | | |
| resort_id | smallint(6) | | |
| priority | tinyint(1) | | |
+--------------+---------------------+------+-----+

If I insert the value "123" in the name field then a new row is added to the table, with a value in the EXTRA_ID field..

what is best ways of finding the value of the EXTRA_ID field, at the moment I do

select extra_id from {table} where name="123";

but the issue I have got now is I have the names the same in different rows

any ideas ?

Graham
Jul 19 '05 #2
If Extra_ID is an autonumber field that is increased whenever a new row is added, then you can use the "Select Last_Insert_ID()" Function.

Just look it up in the docs, it's all there on how to use it.

Brandon
"Graham Mattingley" <gr****@technocom.com> wrote in message news:bn*******************@news.demon.co.uk...
If I insert a value into a table what is the best way to find the Primary Field Value..

+--------------+---------------------+------+-----+
| Field | Type | Null | Key |
+--------------+---------------------+------+-----+
| EXTRA_ID | smallint(6) | | PRI |
| DATE_ADDED | datetime | YES | |
| DATE_AMENDED | datetime | YES | |
| NAME | char(30) | | |
| URL | char(30) | | |
| DESCRIPTION | char(250) | | |
| ACTIVE | char(1) | | |
| ISLAND_ID | tinyint(3) unsigned | | |
| resort_id | smallint(6) | | |
| priority | tinyint(1) | | |
+--------------+---------------------+------+-----+

If I insert the value "123" in the name field then a new row is added to the table, with a value in the EXTRA_ID field..

what is best ways of finding the value of the EXTRA_ID field, at the moment I do

select extra_id from {table} where name="123";

but the issue I have got now is I have the names the same in different rows

any ideas ?

Graham
Jul 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Scott Adams | last post: by
5 posts views Thread by Mark Feller | last post: by
2 posts views Thread by Ben | last post: by
4 posts views Thread by Marc Pelletier | last post: by
3 posts views Thread by Cesar Ronchese | last post: by
20 posts views Thread by Joe | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.