Using User-Defined Variables; Using Foreign Keys - Oracle 5.0 Reference Manual

Table of Contents

Advertisement

SELECT s1.article, dealer, s1.price
FROM shop s1
JOIN (
SELECT article, MAX(price) AS price
FROM shop
GROUP BY article) AS s2
ON s1.article = s2.article AND s1.price = s2.price;
LEFT
JOIN:
SELECT s1.article, s1.dealer, s1.price
FROM shop s1
LEFT JOIN shop s2 ON s1.article = s2.article AND s1.price < s2.price
WHERE s2.article IS NULL;
The
LEFT JOIN
with a greater value and the
s2.price
Syntax".

3.6.5. Using User-Defined Variables

You can employ MySQL user variables to remember results without having to store them in temporary
variables in the client. (See
For example, to find the articles with the highest and lowest price you can do this:
mysql>
SELECT @min_price:=MIN(price),@max_price:=MAX(price) FROM shop;
mysql>
SELECT * FROM shop WHERE price=@min_price OR price=@max_price;
+---------+--------+-------+
| article | dealer | price |
+---------+--------+-------+
|
0003 | D
|
0004 | D
+---------+--------+-------+

3.6.6. Using Foreign Keys

In MySQL,
InnoDB
Storage
Engine", and
A foreign key constraint is not required merely to join two tables. For storage engines other than
InnoDB, it is possible when defining a column to use a
which has no actual effect, and serves only as a memo or comment to you that the column which
you are currently defining is intended to refer to a column in another table. It is extremely important to
realize when using this syntax that:
• MySQL does not perform any sort of
tbl_name
• MySQL does not perform any sort of action on
actions taken on rows in the table which you are defining; in other words, this syntax induces no
ON DELETE
clause as part of the
UPDATE
• This syntax creates a column; it does not create any sort of index or key.
You can use a column so created as a join column, as shown here:

Using User-Defined Variables

works on the basis that when
Section 9.4, "User-Defined
|
1.25 |
| 19.95 |
Note
It is also possible to store the name of a database object such as a table or a
column in a user variable and then to use this variable in an SQL statement;
however, this requires the use of a prepared statement. See
Syntax for Prepared
tables support checking of foreign key constraints. See
Section 1.8.5.4, "Foreign
(or even that
tbl_name
or
behavior whatsoever. (Although you can write an
ON UPDATE
REFERENCES
is at its maximum value, there is no
s1.price
rows values will be NULL. See
s2
Variables".)
Statements", for more information.
Keys".
REFERENCES tbl_name(col_name)
to make sure that
CHECK
itself exists).
such as deleting rows in response to
tbl_name
clause, it is also ignored.)
218
Section 13.2.8.2,
Section 13.5, "SQL
Section 14.2, "The
actually exists in
col_name
ON DELETE
"JOIN
InnoDB
clause,
or
ON

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the 5.0 and is the answer not in the manual?

Questions and answers

This manual is also suitable for:

Mysql 5.0

Table of Contents