LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-10-2006, 06:35 PM   #1
vargadanis
Member
 
Registered: Sep 2006
Posts: 248

Rep: Reputation: 30
MySQL SELECT question - simple


Hi,

I would like to select datas from a table but it often contains the same "title" (with different other fields). I would like to select only once those rows that has the same title field. Eg:
Code:
ID  |  TITLE  |  POST_ID
-------------------------
 1  | Apple   |  4
 2  | Apple   |  9
 3  | Cherry  |  11
In this case I want to select the fields with Apple title only once. Is it possible?
 
Old 10-10-2006, 06:36 PM   #2
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
"select unique"

PS:
Some databases (like mySQL) use "distinct" instead of "unique".
Quote:
EXAMPLE:
select distinct address_city from center_addresses order by address_city;

Last edited by paulsm4; 10-10-2006 at 06:43 PM.
 
Old 10-10-2006, 07:08 PM   #3
vargadanis
Member
 
Registered: Sep 2006
Posts: 248

Original Poster
Rep: Reputation: 30
Ahha...

I tried but it just listed everything again:
Code:
SELECT DISTINCT * FROM phpbb_topics INNER JOIN phpbb_posts ON phpbb_topics.topic_id=phpbb_posts.topic_id  ORDER BY -phpbb_posts.post_time LIMIT 3
What do u think what shall I edit to get it working?
 
Old 10-10-2006, 08:14 PM   #4
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,360

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
select distinct (title), blah, blah
distinct * tries to apply it to every unique combination
 
Old 10-10-2006, 09:00 PM   #5
vargadanis
Member
 
Registered: Sep 2006
Posts: 248

Original Poster
Rep: Reputation: 30
Ok... I solved it with your help. The new code is:
Code:
SELECT DISTINCT phpbb_topics.topic_title, phpbb_topics.topic_id FROM phpbb_topics INNER JOIN phpbb_posts ON phpbb_topics.topic_id=phpbb_posts.topic_id  ORDER BY -phpbb_posts.post_time LIMIT 3
I know that it doesn't say much for those who do not know what tables I was using. If you are interested in visit phpbb.com and install the forum engine.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
MySQL question on sorting (should be simple) BrianK Programming 3 08-09-2006 09:20 PM
another simple question about select() djgerbavore Programming 10 04-15-2006 03:29 PM
MySQL Select Count Question robgo777 Programming 9 01-07-2005 05:54 AM
simple mysql question belorion Linux - Software 1 11-22-2004 05:45 PM
Simple MySQL question dfownz Linux - Software 5 05-08-2004 09:16 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:32 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration