ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
This is an easier (?) alternative:
what if i had a table and i wanted two sets of numbers that are like auto_increment; how would i auto-increment numbers starting from 1 going down from where tbl2.x = 'something', and then do another one starting from 1 where tbl2.x = 'something_else'
this is the original question:
I can't even describe my problem succinctly in the subject of this thread.
Here's what I'm trying to do:
select id from db2.tbl2;
returns:
id
1
2
3
...
(this query already works properly)
select tbl2_id from db1.tbl1 where db1.tbl1.table = 'db2.tbl2';
returns:
same as above.
The problem now is that the second query returns:
tbl2_id
1
1
1
...
I filled out the column tbl2_id by:
update db1.tbl1, db2.tbl2 set db1.tbl1.tbl2_id = db2.tbl2.id where db1.tbl1.table = 'db2.tbl2';
OR
update db1.tbl1 join db2.tbl2 ON (db1.tbl1.table = 'db2.tbl2') set db1.tbl1.tbl2_id = db2.tbl2.id;
Both yield the same result.
Have any idea how to do what I want to do?
Last edited by secretlydead; 10-12-2009 at 03:48 AM.
Please describe your problem more fully. Give us details.
"Auto-increment" fields are really just designed for providing primary-key values... when you need for a row to have a primary key but you really don't care what the value is. (That is to say, "only the computer cares what it is ... not the end-users or the business.)
If the numbers are important, use a separate table of counters ("next_invoice_number", etc...). First you acquire the next number using this table, then you increment the counter, then you use the number when inserting rows into other tables.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.