SQL Select Unique() ?
| From: | James, Yz | Date: | Thu, 19 Apr 2001 20:11:13 +0000 |
| Subject: | SQL Select Unique() ? | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-49413@lists.php.net to get a copy of this message | ||
Hi Guys,
Is there a method of extracting rows from a MySQL table Uniquely (as in only
once) ?..... For example, when a user performs a search, using two words,
it may return the same row twice if the search is spread over two or more
SQL "selections". An example:
If hypothetical row 129 is a Public House, but the public house doubles up
as a restaurant, a search like this might return the same result twice.
Here is our hypothetical pub:
id = 129
name = The Blue Bell Inn
category = Public House
description = The Blue Bell Inn is a hypothetical pub, in the heart of rural
England. Why not visit, have a drink and perhaps even dine in our fine
Restaurant area.
The user might perform the search, searching by "category" OR by
"description". So if they typed "Public House / Restaurant" as the query,
the following would occur:
$sql = "SELECT * FROM table WHERE category LIKE 'Public House / Restaurant'
OR description LIKE 'Public House / Restaurant'";
Surely that would bring the same row back twice..... Is there any way of
selecting from the table just once, without having to restrict the search
facility to something like:
"SELECT * FROM table WHERE category LIKE '%$searchtext%'";
as opposed to having the "OR" in as well?
Thanks, as always,
James.