Expert PHP and Mysql

SELECT IFNULL(NULL,’Value is NULL’) AS result1,
IFNULL(1 > 2, ‘NULL result’) AS result2;

mysql> SELECT NULLIF(TRUE,TRUE) AS istrue,
NULLIF(TRUE,FALSE) AS isfalse,
NULLIF(TRUE,NULL) AS isnull;

MySQL has four logic control operators: AND, OR, NOT, and XOR. Three of these operators also have
shorthand notations: && (AND), || (OR), ! (NOT). These shorthand notations should not be confused
with the Bit operators, which are single characters of & and |.

SELECT IF (2 > 1,’2 is greater than 1’,’2 is not greater than 1’) AS answer;

mysql> SET @value=CONVERT(RAND()* 10, UNSIGNED INTEGER);

mysql> SELECT @value ,
-> CASE
-> WHEN @value < 3 THEN ‘Value is < 3’
-> WHEN @value > 6 THEN ‘Value is > 6’
-> WHEN @value = 3 OR @value = 6 THEN ‘Value is 3 or 6’
-> ELSE ‘Value is 4 or 5’
-> END;

mysql> SELECT IFNULL(NULL,’Value is NULL’) AS result1,
IFNULL(1 > 2, ‘NULL result’) AS result2;

mysql> CREATE TABLE example (
-> currency ENUM(‘USD’,’CAD’,’AUD’) NOT NULL
-> ) ENGINE=InnoDB DEFAULT CHARSET latin1;

mysql> ALTER TABLE flags
-> ADD FOREIGN KEY (color)
-> REFERENCES colors (color)
-> ON DELETE CASCADE;

mysql> SHOW WARNINGS;

mysql> SET SESSION sql_mode=’TRADITIONAL’;

sql_mode=NO_ENGINE_SUBSTITUTION

SELECT DISTINCT f.color
FROM flags f
WHERE EXISTS
(SELECT 1
FROM colors c
WHERE c.color = f.color);

SELECT DISTINCT f.country,
(SELECT GROUP_CONCAT(color)
FROM flags f2
WHERE f2.country = f.country) AS colors
FROM flags f;

你可能感兴趣的:(Expert PHP and Mysql)