0

i have a column in mysql called origin which is type integer(not ascending or descending). All rows have an origin assigned to them can't be duplicated... e.g. two rows with the same origin(integer).


when inserting a new row. Just say row 1 has origin 15 and i'm inserting a new row with the same origin(15) how do i go to the next available integer to prevent a duplicate origin?

Edited by MDanz: n/a

2
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by JRM
0

before you insert, do a query for the origin number that you are about to insert. If the query comes up empty, you can insert the number.

0

before you insert, do a query for the origin number that you are about to insert. If the query comes up empty, you can insert the number.

i've done the part if it comes up empty..

if it is doesn't come up empty how do i insert an available origin number(not used by any in the table)?

0

Maybe i'm not understanding the issue?
I don't know where the "available origins" come from.
My thought was, that you HAD one and wanted to make sure it wasn't already there.
You do a "select" where origin = $myNewTestOrigin. If it's empty, then your test origin can be put into a second "insert" query and insert it..
It's two queries.
Am I missing the point? ( no pun intended)

Edited by JRM: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.