Seemingly Strange Variable Behavior

2001-09-10 Thread Sheridan Saint-Michel

I ran into this and was hoping someone on this list can explain this
behavior to me.

Lets say I have the table table which has id and name, and five rows of
data.

I am using the query
select table.*,if(@count,@count:=@count+1,@count:=1) as count, from table;

What I get is id, name, and five rows of 1's under count.

Now If I do

set @count=NULL;
select table.*,if(@count,@count:=@count+1,@count:=1) as count, from table;

the count column has 1,2,3,4,5

When I do select @count immediately upon opening MySQL it returns NULL.

So why do I get the expected result when I do set @count=NULL; but an entire
column of 1's when I don't... even though @count returns NULL?

Sheridan Saint-Michel
Website Administrator
FoxJet, an ITW Company
www.foxjet.com


-
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




Re: Copying data from one table to another.

2001-09-10 Thread Sheridan Saint-Michel

I think what you are looking for is the Insert...Select statement
http://www.mysql.com/doc/I/N/INSERT_SELECT.html

Sheridan Saint-Michel
Website Administrator
FoxJet, an ITW Company
www.foxjet.com


- Original Message -
From: Eric Spletzer [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Monday, September 10, 2001 4:38 PM
Subject: Copying data from one table to another.


 Hello, I'm a newbie, so pardon my lack of wherewithal with MySQL, and
thanks
 for the help in advance.

 I have two table and I want to copy info from one table to another.  I can
 pull the correct information out with a select statement that looks
 something like this

 Select x1 from tbl1, tbl2 where y1 = y2

 (numbers correspond to different tables)

 This returns a table of the info I want to use.  Logically, what I would
 like to do is:

 Update tbl1 set x1 = x2 where y1 = y2;

 But this won't work because x1 and x2 are from different tables, as are y1
 and y2.  However, I've tried including tbl2 in the update parts, and that
 doesn't work either.  I'm at a loss.

 Thanks for any help.

 -eric spletzer


 -
 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


-
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