PHP MySql Web Hosting

PHP and MySQL Web Development

mysql> SELECT @id := cust_id FROM customers WHERE

Filed under: MySQL Solutions — webmaster @ 8:25 pm

mysql> SELECT @id := cust_id FROM customers WHERE cust_id=’ customer name ‘; mysql> DELETE FROM customers WHERE cust_id = @id; mysql> DELETE FROM orders WHERE cust_id = @id; The preceding SELECT statement assigns a column value to a variable, but variables also can be assigned values from arbitrary expressions. The following statement determines the highest sum of the arms and legs columns in the limbs table and assigns it to the @max_limbs variable: mysql> SELECT @max_limbs := MAX(arms+legs) FROM limbs; Another use for a variable is to save the result from LAST_INSERT_ID( ) after creating a new record in a table that has an AUTO_INCREMENT column: mysql> SELECT @last_id := LAST_INSERT_ID( ); LAST_INSERT_ID( ) returns the value of the new AUTO_INCREMENT value. By saving it in a variable, you can refer to the value several times in subsequent statements, even if you issue other statements that create their own AUTO_INCREMENT values and thus change the value returned by LAST_INSERT_ID( ). This is discussed further in Chapter 11. SQL variables hold single values. If you assign a value to a variable using a statement that returns multiple rows, the value from the last row is used: mysql> SELECT @name := thing FROM limbs WHERE legs = 0; +—————-+ | @name := thing | +—————-+ | squid | | octopus | | fish | | phonograph | +—————-+ mysql> SELECT @name; +————+ | @name | +————+ | phonograph | +————+ If the statement returns no rows, no assignment takes place and the variable retains its previous value. If the variable has not been used previously, that value is NULL: mysql> SELECT @name2 := thing FROM limbs WHERE legs < 0; Empty set (0.00 sec) mysql> SELECT @name2; +——–+ | @name2 | +——–+ | NULL |

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost PHP Web Hosting services

No Comments

No comments yet.

RSS feed for comments on this post. TrackBack URI

Sorry, the comment form is closed at this time.

Powered by PHP MySQL Web Hosting