Jump to content

Ignore duplicate records


RON_ron

Recommended Posts

How do I pull data by ignoring duplicate records?

 

E.g. I've got 100 types of books and a field in mysql saying 'category'. In the books I've got 20 books as history, 5 books as agriculture, etc...

 

I need the data displayed only the types of categories.

history

agriculture

etc...

 

$SomeVar = $_POST['finco'];
$query = "SELECT * FROM  abcs WHERE typesz = '".$SomeVar."' ORDER BY typesz ASC";
$results = mysql_query($query);

$returnS="";
while($line = mysql_fetch_array($results))
{

Link to comment
https://forums.phpfreaks.com/topic/213364-ignore-duplicate-records/
Share on other sites

Hi

 

DISTINCT returns unique rows. So just put a where cause to exclude unwanted rows first.

 

SELECT DISTINCT category
FROM bookTable
WHERE availability = 'YES'

 

Note that if you return other columns of data the code will return distinct combinations. So you could have 2 categories of agriculture returned if the other field was different. Logically if you still want only a single occurrence of each category to be returned then you need to specify which one is returned.

 

All the best

 

Keith

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.