Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.