| Gabriel PREDA 2006-04-03, 7:32 am |
| ------ =_Part_6841_28503480
.1144064177739
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline
First of all... yes... in MySQL variables are declared and used with @
Now for the ":" ... there is no particular role... they're there because
otherwise the SQL parser will be confused...
*SELECT column1, @neededValue=3Dcolum
n2 FROM table_name LIMIT 1*
*SELECT column1, @neededValue:=3Dcolu
mn2 FROM table_name LIMIT 1*
In the first SQL the parser would test whether @neededValue is equal tot th=
e
value in column2 instead of assigning to @neededValue the value from column=
2
This confusion can happen only in SELECT statements... so you are required
to add ":" only in SELECT statements.
In SET statements you don't need that... you can write:
*SET @last =3D last_insert_id()*
Or with values from outside MySQL:
*SET @iNeedThis =3D 'someText';*
Then use both in an insert statement:
*INSERT INTO table (lid, txt) VALUES (@last, @iNeedThis);*
Hope this cleared up things !
--
Gabriel PREDA
Senior Web Developer
On 4/3/06, Yemi Obembe <ray@ngbot.com> wrote:
>
> Got the snippet from the mysql website:
>
> select @last :=3D last_insert_id()
> i av the hunch that is to assign the variable 'last' to the
> last_insert_id(). Im i right? is placing @ before a word mysql's way of
> declaring variables? what's the work of the colon preceeding the equal
> sign?
>
------ =_Part_6841_28503480
.1144064177739--
|