Re: SQL Select Unique() ?

From: Date: Fri, 20 Apr 2001 01:25:13 +0000
Subject: Re: SQL Select Unique() ?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-49474@lists.php.net to get a copy of this message
On Fri, 20 Apr 2001 05:41, James, Yz wrote: > 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'"; This of course won't select the hypothetical cae in question. Perhaps you might be betterr off using a dropdown list built from the table of categories that you are using as a lookup table (you are, aren't you?) > 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%'"; Again, that won't work in this case - you might want to separate the words in the search string and do an OR search on all the words. > > as opposed to having the "OR" in as well? > > Thanks, as always, > > James. Broadly, in this type of situation the row will only be returned once notwithstanding that it might meet several citeria. -- David Robley | WEBMASTER & Mail List Admin RESEARCH CENTRE FOR INJURY STUDIES | http://www.nisu.flinders.edu.au/ AusEinet | http://auseinet.flinders.edu.au/ Flinders University, ADELAIDE, SOUTH AUSTRALIA

« previous php.general (#49474) next »