Hacked By AnonymousFox
( #JOIN MySQL supports the following JOIN syntaxes for the table_references
part of SELECT statements and multiple-table DELETE and UPDATE
statements:
table_references:
table_reference [, table_reference] ...
table_reference:
table_factor
| join_table
table_factor:
tbl_name [[AS] alias]
[{USE|IGNORE|FORCE} INDEX (key_list)]
| ( table_references )
| { OJ table_reference LEFT OUTER JOIN table_reference
ON conditional_expr }
join_table:
table_reference [INNER | CROSS] JOIN table_factor [join_condition]
| table_reference STRAIGHT_JOIN table_factor
| table_reference STRAIGHT_JOIN table_factor ON condition
| table_reference LEFT [OUTER] JOIN table_reference join_condition
| table_reference NATURAL [LEFT [OUTER]] JOIN table_factor
| table_reference RIGHT [OUTER] JOIN table_reference join_condition
| table_reference NATURAL [RIGHT [OUTER]] JOIN table_factor
join_condition:
ON conditional_expr
| USING (column_list)
A table reference is also known as a join expression.
The syntax of table_factor is extended in comparison with the SQL
Standard. The latter accepts only table_reference, not a list of them
inside a pair of parentheses.
This is a conservative extension if we consider each comma in a list of
table_reference items as equivalent to an inner join. For example:
SELECT * FROM t1 LEFT JOIN (t2, t3, t4)
ON (t2.a=t1.a AND t3.b=t1.b AND t4.c=t1.c)
is equivalent to:
SELECT * FROM t1 LEFT JOIN (t2 CROSS JOIN t3 CROSS JOIN t4)
ON (t2.a=t1.a AND t3.b=t1.b AND t4.c=t1.c)
In MySQL, CROSS JOIN is a syntactic equivalent to INNER JOIN (they can
replace each other). In standard SQL, they are not equivalent. INNER
JOIN is used with an ON clause, CROSS JOIN is used otherwise.
In versions of MySQL prior to 5.0.1, parentheses in table_references
were just omitted and all join operations were grouped to the left. In
general, parentheses can be ignored in join expressions containing only
inner join operations. As of 5.0.1, nested joins are allowed (see
[nested-joins]).
Further changes in join processing were made in 5.0.12 to make MySQL
more compliant with standard SQL. These charges are described later in
this section.
a SELECT table1.* FROM table1
LEFT JOIN table2 ON table1.id=table2.id
WHERE table2.id IS NULL;
join" HEX! LSyntax:
HEX(N_or_S)
If N_or_S is a number, returns a string representation of the
hexadecimal value of N, where N is a longlong (BIGINT) number. This is
equivalent to CONV(N,10,16).
If N_or_S is a string, returns a hexadecimal string representation of
N_or_S where each character in N_or_S is converted to two hexadecimal
digits.
} mysql> SELECT HEX(255);
-> 'FF'
mysql> SELECT 0x616263;
-> 'abc'
mysql> SELECT HEX('abc');
-> 616263
string-functionsD " REPLACE! Syntax:
REPLACE(str,from_str,to_str)
Returns the string str with all occurrences of the string from_str
replaced by the string to_str. REPLACE() performs a case-sensitive
match when searching for from_str.
Q mysql> SELECT REPLACE('www.mysql.com', 'w', 'Ww');
-> 'WwWwWw.mysql.com'
string-functions 2 CONTAINS O Contains(g1,g2)
Returns 1 or 0 to indicate whether g1 completely contains g2.
<functions-that-test-spatial-relationships-between-geometries ]" SRID SRID(g)
Returns an integer indicating the Spatial Reference System ID for the
geometry value g.
In MySQL, the SRID value is just an integer associated with the
geometry value. All calculations are done assuming Euclidean (planar)
geometry.
7mysql> SELECT SRID(GeomFromText('LineString(1 1,2 2)',101));
+-----------------------------------------------+
| SRID(GeomFromText('LineString(1 1,2 2)',101)) |
+-----------------------------------------------+
| 101 |
+-----------------------------------------------+
#general-geometry-property-functions 2 CURRENT_TIMESTAMP r Syntax:
CURRENT_TIMESTAMP, CURRENT_TIMESTAMP()
CURRENT_TIMESTAMP and CURRENT_TIMESTAMP() are synonyms for NOW().
date-and-time-functions2 VARIANCE Syntax:
VARIANCE(expr)
Returns the population standard variance of expr. This is an extension
to standard SQL. As of MySQL 5.0.3, the standard SQL function VAR_POP()
can be used instead.
VARIANCE() returns NULL if there were no matching rows.
group-by-functions 2 VAR_SAMP Syntax:
VAR_SAMP(expr)
Returns the sample variance of expr. That is, the denominator is the
number of rows minus one. This function was added in MySQL 5.0.3.
VAR_SAMP() returns NULL if there were no matching rows.
group-by-functions" CONCAT! Syntax:
CONCAT(str1,str2,...)
Returns the string that results from concatenating the arguments. May
have one or more arguments. If all arguments are non-binary strings,
the result is a non-binary string. If the arguments include any binary
strings, the result is a binary string. A numeric argument is converted
to its equivalent binary string form; if you want to avoid that, you
can use an explicit type cast, as in this example:
SELECT CONCAT(CAST(int_col AS CHAR), char_col);
CONCAT() returns NULL if any argument is NULL.
mysql> SELECT CONCAT('My', 'S', 'QL');
-> 'MySQL'
mysql> SELECT CONCAT('My', NULL, 'QL');
-> NULL
mysql> SELECT CONCAT(14.3);
-> '14.3'
string-functions2 GEOMETRY HIERARCHY Geometry is the base class. It is an abstract class. The instantiable
subclasses of Geometry are restricted to zero-, one-, and
two-dimensional geometric objects that exist in two-dimensional
coordinate space. All instantiable geometry classes are defined so that
valid instances of a geometry class are topologically closed (that is,
all defined geometries include their boundary).
The base Geometry class has subclasses for Point, Curve, Surface, and
GeometryCollection:
o Point represents zero-dimensional objects.
o Curve represents one-dimensional objects, and has subclass
LineString, with sub-subclasses Line and LinearRing.
o Surface is designed for two-dimensional objects and has subclass
Polygon.
o GeometryCollection has specialized zero-, one-, and two-dimensional
collection classes named MultiPoint, MultiLineString, and
MultiPolygon for modeling geometries corresponding to collections of
Points, LineStrings, and Polygons, respectively. MultiCurve and
MultiSurface are introduced as abstract superclasses that generalize
the collection interfaces to handle Curves and Surfaces.
Geometry, Curve, Surface, MultiCurve, and MultiSurface are defined as
non-instantiable classes. They define a common set of methods for their
subclasses and are included for extensibility.
Point, LineString, Polygon, GeometryCollection, MultiPoint,
MultiLineString, and MultiPolygon are instantiable classes.
gis-geometry-class-hierarchy "
CHAR FUNCTION! Syntax:
CHAR(N,... [USING charset_name])
CHAR() interprets each argument N as an integer and returns a string
consisting of the characters given by the code values of those
integers. NULL values are skipped.
As of MySQL 5.0.15, CHAR() arguments larger than 255 are converted into
multiple result bytes. For example, CHAR(256) is equivalent to
CHAR(1,0), and CHAR(256*256) is equivalent to CHAR(1,0,0):
mysql> SELECT HEX(CHAR(1,0)), HEX(CHAR(256));
+----------------+----------------+
| HEX(CHAR(1,0)) | HEX(CHAR(256)) |
+----------------+----------------+
| 0100 | 0100 |
+----------------+----------------+
mysql> SELECT HEX(CHAR(1,0,0)), HEX(CHAR(256*256));
+------------------+--------------------+
| HEX(CHAR(1,0,0)) | HEX(CHAR(256*256)) |
+------------------+--------------------+
| 010000 | 010000 |
+------------------+--------------------+
By default, CHAR() returns a binary string. To produce a string in a
given character set, use the optional USING clause:
mysql> SELECT CHARSET(CHAR(0x65)), CHARSET(CHAR(0x65 USING utf8));
+---------------------+--------------------------------+
| CHARSET(CHAR(0x65)) | CHARSET(CHAR(0x65 USING utf8)) |
+---------------------+--------------------------------+
| binary | utf8 |
+---------------------+--------------------------------+
If USING is given and the result string is illegal for the given
character set, a warning is issued. Also, if strict SQL mode is
enabled, the result from CHAR() becomes NULL.
Before MySQL 5.0.15, CHAR() returns a string in the connection
character set and the USING clause is unavailable. In addition, each
argument is interpreted modulo 256, so CHAR(256) and CHAR(256*256) both
are equivalent to CHAR(0).
o mysql> SELECT CHAR(77,121,83,81,'76');
-> 'MySQL'
mysql> SELECT CHAR(77,77.3,'77.3');
-> 'MMM'
string-functions12 DATETIME DATETIME
A date and time combination. The supported range is '1000-01-01
00:00:00' to '9999-12-31 23:59:59'. MySQL displays DATETIME values in
'YYYY-MM-DD HH:MM:SS' format, but allows you to assign values to
DATETIME columns using either strings or numbers.
date-and-time-type-overview ` 2 OPEN# M Syntax:
OPEN cursor_name
This statement opens a previously declared cursor.
open "
SHOW CREATE PROCEDURE Syntax:
SHOW CREATE {PROCEDURE | FUNCTION} sp_name
This statement is a MySQL extension. Similar to SHOW CREATE TABLE, it
returns the exact string that can be used to re-create the named
routine.
mysql> SHOW CREATE FUNCTION test.hello\G
*************************** 1. row ***************************
Function: hello
sql_mode:
Create Function: CREATE FUNCTION `test`.`hello`(s CHAR(20)) RETURNS CHAR(50)
RETURN CONCAT('Hello, ',s,'!')
show-create-procedure k2 INTEGER D INTEGER[(M)] [UNSIGNED] [ZEROFILL]
This type is a synonym for INT.
numeric-type-overview " LOWER! Syntax:
LOWER(str)
Returns the string str with all characters changed to lowercase
according to the current character set mapping. The default is latin1
(cp1252 West European).
A mysql> SELECT LOWER('QUADRATICALLY');
-> 'quadratically'
string-functions2 CREATE TRIGGER Syntax:
CREATE
[DEFINER = { user | CURRENT_USER }]
TRIGGER trigger_name trigger_time trigger_event
ON tbl_name FOR EACH ROW trigger_stmt
This statement creates a new trigger. A trigger is a named database
object that is associated with a table, and that activates when a
particular event occurs for the table. CREATE TRIGGER was added in
MySQL 5.0.2. Currently, its use requires the SUPER privilege.
The trigger becomes associated with the table named tbl_name, which
must refer to a permanent table. You cannot associate a trigger with a
TEMPORARY table or a view.
When the trigger is activated, the DEFINER clause determines the
privileges that apply, as described later in this section.
trigger_time is the trigger action time. It can be BEFORE or AFTER to
indicate that the trigger activates before or after the statement that
activated it.
trigger_event indicates the kind of statement that activates the
trigger. The trigger_event can be one of the following:
o INSERT: The trigger is activated whenever a new row is inserted into
the table; for example, through INSERT, LOAD DATA, and REPLACE
statements.
o UPDATE: The trigger is activated whenever a row is modified; for
example, through UPDATE statements.
o DELETE: The trigger is activated whenever a row is deleted from the
table; for example, through DELETE and REPLACE statements. However,
DROP TABLE and TRUNCATE statements on the table do not activate this
trigger, because they do not use DELETE. See [truncate].
create-trigger 2 SHOW COLUMNS Syntax:
SHOW [FULL] COLUMNS FROM tbl_name [FROM db_name] [LIKE 'pattern']
SHOW COLUMNS displays information about the columns in a given table.
It also works for views as of MySQL 5.0.1.
If the data types differ from what you expect them to be based on your
CREATE TABLE statement, note that MySQL sometimes changes data types
when you create or alter a table. The conditions for which this occurs
are described in [silent-column-changes].
The FULL keyword causes the output to include the privileges you have
as well as any per-column comments for each column.
You can use db_name.tbl_name as an alternative to the tbl_name FROM
db_name syntax. In other words, these two statements are equivalent:
mysql> SHOW COLUMNS FROM mytable FROM mydb;
mysql> SHOW COLUMNS FROM mydb.mytable;
SHOW FIELDS is a synonym for SHOW COLUMNS. You can also list a table's
columns with the mysqlshow db_name tbl_name command.
The DESCRIBE statement provides information similar to SHOW COLUMNS.
See [describe].
show-columns " MONTH G Syntax:
MONTH(date)
Returns the month for date, in the range 0 to 12.
0 mysql> SELECT MONTH('1998-02-03');
-> 2
date-and-time-functions 2 TINYINT { TINYINT[(M)] [UNSIGNED] [ZEROFILL]
A very small integer. The signed range is -128 to 127. The unsigned
range is 0 to 255.
numeric-type-overview d 2
SHOW TRIGGERS ?Syntax:
SHOW TRIGGERS [FROM db_name] [LIKE expr]
SHOW TRIGGERS lists the triggers currently defined on the MySQL server.
This statement requires the SUPER privilege. It was implemented in
MySQL 5.0.10.
For the trigger ins_sum as defined in [using-triggers], the output of
this statement is as shown here:
mysql> SHOW TRIGGERS LIKE 'acc%'\G
*************************** 1. row ***************************
Trigger: ins_sum
Event: INSERT
Table: account
Statement: SET @sum = @sum + NEW.amount
Timing: BEFORE
Created: NULL
sql_mode:
Definer: myname@localhost
show-triggers2 MASTER_POS_WAIT
Syntax:
MASTER_POS_WAIT(log_name,log_pos[,timeout])
This function is useful for control of master/slave synchronization. It
blocks until the slave has read and applied all updates up to the
specified position in the master log. The return value is the number of
log events the slave had to wait for to advance to the specified
position. The function returns NULL if the slave SQL thread is not
started, the slave's master information is not initialized, the
arguments are incorrect, or an error occurs. It returns -1 if the
timeout has been exceeded. If the slave SQL thread stops while
MASTER_POS_WAIT() is waiting, the function returns NULL. If the slave
is past the specified position, the function returns immediately.
miscellaneous-functions?" REGEXP! Syntax:
expr REGEXP pat expr RLIKE pat
Performs a pattern match of a string expression expr against a pattern
pat. The pattern can be an extended regular expression. The syntax for
regular expressions is discussed in [regexp]. Returns 1 if expr matches
pat; otherwise it returns 0. If either expr or pat is NULL, the result
is NULL. RLIKE is a synonym for REGEXP, provided for mSQL
compatibility.
The pattern need not be a literal string. For example, it can be
specified as a string expression or table column.
Note: Because MySQL uses the C escape syntax in strings (for example,
`\n' to represent the newline character), you must double any `\' that
you use in your REGEXP strings.
REGEXP is not case sensitive, except when used with binary strings.
mysql> SELECT 'Monty!' REGEXP 'm%y%%';
-> 0
mysql> SELECT 'Monty!' REGEXP '.*';
-> 1
mysql> SELECT 'new*\n*line' REGEXP 'new\\*.\\*line';
-> 1
mysql> SELECT 'a' REGEXP 'A', 'a' REGEXP BINARY 'A';
-> 1 0
mysql> SELECT 'a' REGEXP '^[a-d]';
-> 1
string-comparison-functions 92 IF STATEMENT# Syntax:
IF search_condition THEN statement_list
[ELSEIF search_condition THEN statement_list] ...
[ELSE statement_list]
END IF
IF implements a basic conditional construct. If the search_condition
evaluates to true, the corresponding SQL statement list is executed. If
no search_condition matches, the statement list in the ELSE clause is
executed. Each statement_list consists of one or more statements.
Note: There is also an IF() function, which differs from the IF
statement described here. See [control-flow-functions].
if-statement " ^ Syntax:
^
Bitwise XOR:
g mysql> SELECT 1 ^ 1;
-> 0
mysql> SELECT 1 ^ 0;
-> 1
mysql> SELECT 11 ^ 3;
-> 8
bit-functions 2 DROP VIEW$ Syntax:
DROP VIEW [IF EXISTS]
view_name [, view_name] ...
[RESTRICT | CASCADE]
DROP VIEW removes one or more views. You must have the DROP privilege
for each view.
The IF EXISTS clause prevents an error from occurring for views that
don't exist. When this clause is given, a NOTE is generated for each
non-existent view. See [show-warnings].
RESTRICT and CASCADE, if given, are parsed and ignored.
drop-view -" DATE OPERATIONS Syntax:
DATE_ADD(date,INTERVAL expr type), DATE_SUB(date,INTERVAL expr type)
These functions perform date arithmetic. date is a DATETIME or DATE
value specifying the starting date. expr is an expression specifying
the interval value to be added or subtracted from the starting date.
expr is a string; it may start with a `-' for negative intervals. type
is a keyword indicating how the expression should be interpreted.
Umysql> SELECT '1997-12-31 23:59:59' + INTERVAL 1 SECOND;
-> '1998-01-01 00:00:00'
mysql> SELECT INTERVAL 1 DAY + '1997-12-31';
-> '1998-01-01'
mysql> SELECT '1998-01-01' - INTERVAL 1 SECOND;
-> '1997-12-31 23:59:59'
mysql> SELECT DATE_ADD('1997-12-31 23:59:59',
-> INTERVAL 1 SECOND);
-> '1998-01-01 00:00:00'
mysql> SELECT DATE_ADD('1997-12-31 23:59:59',
-> INTERVAL 1 DAY);
-> '1998-01-01 23:59:59'
mysql> SELECT DATE_ADD('1997-12-31 23:59:59',
-> INTERVAL '1:1' MINUTE_SECOND);
-> '1998-01-01 00:01:00'
mysql> SELECT DATE_SUB('1998-01-01 00:00:00',
-> INTERVAL '1 1:1:1' DAY_SECOND);
-> '1997-12-30 22:58:59'
mysql> SELECT DATE_ADD('1998-01-01 00:00:00',
-> INTERVAL '-1 10' DAY_HOUR);
-> '1997-12-30 14:00:00'
mysql> SELECT DATE_SUB('1998-01-02', INTERVAL 31 DAY);
-> '1997-12-02'
mysql> SELECT DATE_ADD('1992-12-31 23:59:59.000002',
-> INTERVAL '1.999999' SECOND_MICROSECOND);
-> '1993-01-01 00:00:01.000001'
date-and-time-functions 2 WITHIN M Within(g1,g2)
Returns 1 or 0 to indicate whether g1 is spatially within g2.
<functions-that-test-spatial-relationships-between-geometries h " WEEK }Syntax:
WEEK(date[,mode])
This function returns the week number for date. The two-argument form
of WEEK() allows you to specify whether the week starts on Sunday or
Monday and whether the return value should be in the range from 0 to 53
or from 1 to 53. If the mode argument is omitted, the value of the
default_week_format system variable is used. See
[server-system-variables].
mysql> SELECT WEEK('1998-02-20');
-> 7
mysql> SELECT WEEK('1998-02-20',0);
-> 7
mysql> SELECT WEEK('1998-02-20',1);
-> 8
mysql> SELECT WEEK('1998-12-31',1);
-> 53
date-and-time-functions2 PREPARE ~Syntax:
PREPARE stmt_name FROM preparable_stmt
The PREPARE statement prepares a statement and assigns it a name,
stmt_name, by which to refer to the statement later. Statement names
are not case sensitive. preparable_stmt is either a string literal or a
user variable that contains the text of the statement. The text must
represent a single SQL statement, not multiple statements. Within the
statement, `?' characters can be used as parameter markers to indicate
where data values are to be bound to the query later when you execute
it. The `?' characters should not be enclosed within quotes, even if
you intend to bind them to string values. Parameter markers can be used
only where data values should appear, not for SQL keywords,
identifiers, and so forth.
If a prepared statement with the given name already exists, it is
deallocated implicitly before the new statement is prepared. This means
that if the new statement contains an error and cannot be prepared, an
error is returned and no statement with the given name exists.
The scope of a prepared statement is the client session within which it
is created. Other clients cannot see it.
sqlps2 LOCK Syntax:
LOCK TABLES
tbl_name [AS alias] {READ [LOCAL] | [LOW_PRIORITY] WRITE}
[, tbl_name [AS alias] {READ [LOCAL] | [LOW_PRIORITY] WRITE}] ...
UNLOCK TABLES
LOCK TABLES locks tables for the current thread. If any of the tables
are locked by other threads, it blocks until all locks can be acquired.
UNLOCK TABLES releases any locks held by the current thread. All tables
that are locked by the current thread are implicitly unlocked when the
thread issues another LOCK TABLES, or when the connection to the server
is closed.
A table lock protects only against inappropriate reads or writes by
other clients. The client holding the lock, even a read lock, can
perform table-level operations such as DROP TABLE.
lock-tables 2 RESET SLAVE Syntax:
RESET SLAVE
RESET SLAVE makes the slave forget its replication position in the
master's binary logs. This statement is meant to be used for a clean
start: It deletes the master.info and relay-log.info files, all the
relay logs, and starts a new relay log.
Note: All relay logs are deleted, even if they have not been completely
executed by the slave SQL thread. (This is a condition likely to exist
on a replication slave if you have issued a STOP SLAVE statement or if
the slave is highly loaded.)
Connection information stored in the master.info file is immediately
reset using any values specified in the corresponding startup options.
This information includes values such as master host, master port,
master user, and master password. If the slave SQL thread was in the
middle of replicating temporary tables when it was stopped, and RESET
SLAVE is issued, these replicated temporary tables are deleted on the
slave.
reset-slave 2 POLYGON Polygon(ls1,ls2,...)
Constructs a WKB Polygon value from a number of WKB LineString
arguments. If any argument does not represent the WKB of a LinearRing
(that is, not a closed and simple LineString) the return value is NULL.
gis-mysql-specific-functions "! MINUTE I Syntax:
MINUTE(time)
Returns the minute for time, in the range 0 to 59.
8 mysql> SELECT MINUTE('98-02-03 10:05:03');
-> 5
date-and-time-functions ]2"