RE: [PHP-DB] How I can use multiple results in MySQL
| From: | Mark Roedel | Date: | Mon, 23 Apr 2001 13:18:02 +0000 |
| Subject: | RE: [PHP-DB] How I can use multiple results in MySQL | ||
| Groups: | php.db | ||
| Request: | Send a blank email to php-db+get-8812@lists.php.net to get a copy of this message | ||
> -----Original Message-----
> From: Yevgeny Dyatlov [mailto:rus_php_user@mail.ru]
> Sent: Monday, April 23, 2001 8:05 AM
> To: PHP-DB
> Subject: [PHP-DB] How I can use multiple results in MySQL
>
>
> I'm cann't using query to MySQL like this:
>
> SELECT name FROM cia WHERE region =
> (SELECT region FROM table WHERE name = 'Brazil');
>
> And
>
> SELECT name FROM table WHERE count =
> (SELECT max(count) FROM table);
>
> I want to select COLUMN_NAME in TABLE where ID is max,
> how I can do it?
MySQL doesn't support sub-selects.
However, in many cases you can get the same result by either
reorganizing your queries or creating a temporary table. For more info,
see
http://www.mysql.com/doc/M/i/Missing_Sub-selects.html
For example, your first query, rearranged to use joins, might wind up
looking something like
SELECT cia.name
FROM cia, table
WHERE cia.region = table.region
AND table.name='Brazil'
For the second, I'd do something like
SELECT name
FROM table
ORDER BY count DESC
LIMIT 1
---
Mark Roedel (roedelm@letu.edu) || "There cannot be a crisis next week.
Systems Programmer / WebMaster || My schedule is already full."
LeTourneau University || -- Henry Kissinger