Jump to content

How to eliminate duplicate entries in DB results of query?


modigy

Recommended Posts

Hey all,

I've received so much help.  Now I have another question.  I have a query...both a FULLTEXT search and a multiple dropdown box search.  But the client DB contains multiple book 'title' entries.  I would like to know how to eliminate the duplicate entries in the DB and just get the 'Unique' entries with regard to the 'title' fields of the DB?

Here's my 'partial' mysql/php code:

[code] <?php

$database=mysql_pconnect('localhost','jandj_root');
mysql_select_db('books');

if ($topic) {
$query="select * from jandj_jandj.books where theme = '".$topic."' and referenceNum=0";
}

if ($title) {
if ($title == "a-f")
$query="select * from jandj_jandj.books where (title between 'a' and 'f') and referenceNum=0";
if ($title == "g-l")
$query="select * from jandj_jandj.books where (title between 'g' and 'l') and referenceNum=0";
if ($title == "m-r")
$query="select * from jandj_jandj.books where (title between 'm' and 'r') and referenceNum=0";
if ($title == "s-z")
$query="select * from jandj_jandj.books where (title between 's' and 'z') and referenceNum=0";

}

if ($author) {
if ($author == "a-f")
$query="select * from jandj_jandj.books where (author between 'a' and 'f') and referenceNum=0";
if ($author == "g-l")
$query="select * from jandj_jandj.books where (author between 'g' and 'l') and referenceNum=0";
if ($author == "m-r")
$query="select * from jandj_jandj.books where (author between 'm' and 'r') and referenceNum=0";
if ($author == "s-z")
$query="select * from jandj_jandj.books where (author between 's' and 'z') and referenceNum=0";

}

// query defined above
$result=mysql_query($query);
?>[/code]

How might I adjust this code to 'eliminate' duplicates of 'title' field in the DB?  If the results include a book called 'Clifford the Big Red Dog' I don't want 5 of these results...just the 'Unique' book 'title'.  Later in the code I have pagination.  Currently the query and the pagination works great, but because there are more than one entries for the same book 'title' the query creates listings that are unecessary for the USER.

Any help and ALL help is appreciated in advance.


Cheers,



M
Thanks Guys!!

This is what I ended up with and it was a big help?

[code]
<?php

if ($topic) {
$query="select * from jandj_jandj.books where theme = '".$topic."' and referenceNum=0 GROUP BY 'title' ASC";
}

if ($title) {
if ($title == "a-f")
$query="select * from jandj_jandj.books where (title between 'a' and 'f') and referenceNum=0 GROUP BY 'title' ASC";
if ($title == "g-l")
$query="select * from jandj_jandj.books where (title between 'g' and 'l') and referenceNum=0 GROUP BY 'title' ASC";
if ($title == "m-r")
$query="select * from jandj_jandj.books where (title between 'm' and 'r') and referenceNum=0 GROUP BY 'title' ASC";
if ($title == "s-z")
$query="select * from jandj_jandj.books where (title between 's' and 'z') and referenceNum=0 GROUP BY 'title' ASC";

}

if ($author) {
if ($author == "a-f")
$query="select * from jandj_jandj.books where (author between 'a' and 'f') and referenceNum=0 GROUP BY 'author' ASC";
if ($author == "g-l")
$query="select * from jandj_jandj.books where (author between 'g' and 'l') and referenceNum=0 GROUP BY 'author' ASC";
if ($author == "m-r")
$query="select * from jandj_jandj.books where (author between 'm' and 'r') and referenceNum=0 GROUP BY 'author' ASC";
if ($author == "s-z")
$query="select * from jandj_jandj.books where (author between 's' and 'z') and referenceNum=0 GROUP BY 'author' ASC";

}
?>
[/code]

Again much appreciated! ;D


M

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.