Jump to content

[SOLVED] Show one result


ctcmedia

Recommended Posts

Crappy title :)

 

What I have is a database of say 791 results and I am trying to sort them out into alphabetical order now I have got the query working but there are duplicate results. What I mean by that is that it is a list of programmes so just say for a there will be about 7 results for one programme but different episodes. How would I only show one result for one programme?

 

Thanks

 

 

Link to comment
Share on other sites

I see that would work if I am wanting one programme but what it is

 

<programme>
    <AZ letter="A">
    <?php
    $queryA = mysql_query("SELECT * FROM programme WHERE title LIKE 'A%'");
    while($rowA=mysql_fetch_array($queryA, MYSQL_ASSOC)){
    ?>
    <title><?=$rowA['title']?></title>
    <description><?=$rowA['description']?></description>
    <pID><?=$rowA['pID']?></pID>
    <?php  } ?>
    </AZ>

</programme>

 

So on and so forth. Since I have this updating the db every hour I wont know what show to look for to put into distinct

Link to comment
Share on other sites

Hi thanks I tried but it wont get me the full row. for instance I am using

 

SELECT DISTINCT title FROM programme WHERE title LIKE 'A%'

 

it works for just bringing back the title but I am needing one more item to get me to a result page which is pid now when I use the following

 

SELECT DISTINCT title, pid FROM programme WHERE title LIKE 'A%'

 

It does what it was before and list everything

 

any ideas?

 

 

 

 

Link to comment
Share on other sites

Hi

 

Is pid unique for a programme or for an episode? If for a programme then it should be fine. If it is for an episode then you need to specify which one you are interested in.

 

Eg, something like:-

 

SELECT title, MIN(pid) FROM programme WHERE title LIKE 'A%' GROUP BY title

 

If you want more than that then probably something like:-

 

SELECT a.*

FROM programme a

INNER JOIN (SELECT title, MIN(pid) AS MinPid FROM programme WHERE title LIKE 'A%' GROUP BY title) b

ON a.title = b.title AND a.pid = b.MinPid

 

All the best

 

Keith

Link to comment
Share on other sites

THANK YOU KEITH

 

this one done the trick

 

SELECT a.*

FROM programme a

INNER JOIN (SELECT title, MIN(pid) AS MinPid FROM programme WHERE title LIKE 'A%' GROUP BY title) b

ON a.title = b.title AND a.pid = b.MinPid

 

 

Sorry for being a pain my brain has been slow for a good few weeks

 

 

Thanks again

 

 

Link to comment
Share on other sites

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.