Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

MySQL identical fields

How can I get MySQL to discount identical fields?



3:21 am on Jun 1, 2008 (gmt 0)

5+ Year Member

My CMS is coming along, but I've run into a problem.

My system gives each item a unique id (auto_increment). Each item is also identified by its title. There may be more than one page in an item; in that case, each page gets its own row. As a result, there are some rows that have identical titles. The unique id is not used by my script and is merely there to ensure no two rows are identical.

I want now to be able to create a list of all my items, but the catch is I don't want items with multiple pages to be listed more than once. Only the first page in an item shall be displayed.

Is there any way with MySQL or PHP to filter the extra rows out such that when everything is processed, there is only one instance of each title in my list?

This is for the backened, so I'm not really concerned with the number of queries, but is there an efficient way to do this?


6:28 am on Jun 1, 2008 (gmt 0)

10+ Year Member

Select DISTINCT title from pages where title = $title ?

Jaunty Edward

7:59 am on Jun 1, 2008 (gmt 0)

10+ Year Member

Select * from pages group by title order by id

that will show each title once and you can show the first or last item with the same title by using order by id desc or asc



12:27 pm on Jun 1, 2008 (gmt 0)

5+ Year Member

Thanks, those both work well. I never could have found those on Google :D.

I ended up using the GROUP BY method, because after some searching I ran across COUNT(), which would even let me display how many pages were in each item.

Thanks again!


Featured Threads

Hot Threads This Week

Hot Threads This Month