SET @var and insert that as cunting var into table with insert select

2007-02-02 Thread Barry

Hello Everyone!

I am having a big problem with counting inserting rows.

This is my Query:

SELECT MAX(id) INTO @maxid FROM table1; // @maxid is now  44

INSERT INTO table2 (orderid, someothervars)
SELECT @maxid +1, blahvar FROM table3;

Okay my problem is, how do i increase the maxid?

like that.

table2:

| id | orderid | someothervars
++-+--+
|1   |44   | blah |
|2   |45   | blah |
|3   |46   | blah |
|4   |47   | blah |
|5   |48   | blah |



And so on.

Anyone has an idea how to do something like that?

I think it works somehow with SET @maxid = @maxid +1

But i fail combining it with INSERT SELECT :/

Any help is greatly appriciated =)

My best wishes
Barry

--
Smileys rule (cX.x)C --o(^_^o)
Dance for me! ^(^_^)o (o^_^)o o(^_^)^ o(^_^o)

--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]



Re: SET @var and insert that as cunting var into table with insert select

2007-02-02 Thread Barry

Barry schrieb:

Hello Everyone!


i forgot i am using MySQL 4.11

Greetings
Barry

--
Smileys rule (cX.x)C --o(^_^o)
Dance for me! ^(^_^)o (o^_^)o o(^_^)^ o(^_^o)

--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]



Re: SET @var and insert that as cunting var into table with insert select

2007-02-02 Thread DuĊĦan Pavlica



Barry napsal(a):

Hello Everyone!

I am having a big problem with counting inserting rows.

This is my Query:

SELECT MAX(id) INTO @maxid FROM table1; // @maxid is now  44

INSERT INTO table2 (orderid, someothervars)
SELECT @maxid +1, blahvar FROM table3;


try
select @maxid:=max(id)-1 from table1;
insert into table2 (orderid, someothervars)
SELECT @maxid:[EMAIL PROTECTED] +1, blahvar FROM table3;

dusan

--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]