problems with distinct

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
grudz
Forum Commoner
Posts: 68
Joined: Thu Dec 04, 2003 12:52 pm

problems with distinct

Post by grudz »

here is my code

Code: Select all

$query_forum = "SELECT DISTINCT question_title FROM forum ORDER BY `date` DESC";
basically, this makes the users see on the php page the different info from the 'qustion_title' column. thats exactly what i wanted, but on this page, i also have different columns from that table that i want to show, not just 'question_title'

how do i keep this code, but write that i also want the other columns

thank you in advance
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

Code: Select all

$query_forum = "SELECT DISTINCT question_title, other_column, some_other_column FROM forum ORDER BY `date` DESC";
Huh?
grudz
Forum Commoner
Posts: 68
Joined: Thu Dec 04, 2003 12:52 pm

Post by grudz »

doesnt work......its logical though
grudz
Forum Commoner
Posts: 68
Joined: Thu Dec 04, 2003 12:52 pm

Post by grudz »

anybody have any ideas...please....
Draco_03
Forum Regular
Posts: 577
Joined: Fri Aug 15, 2003 12:25 pm
Location: Montreal, Canada

Post by Draco_03 »

should work... giveus a bit more of your code and tell us what is the other colomn you want to show
ps : you can use

Code: Select all

instead of

Code: Select all

when showing php code
grudz
Forum Commoner
Posts: 68
Joined: Thu Dec 04, 2003 12:52 pm

here it is

Post by grudz »

Code: Select all

<?php
mysql_select_db($database_cnpa, $cnpa);
$query_forum = "SELECT DISTINCT question_title FROM forum ORDER BY `date` DESC";
$forum = mysql_query($query_forum, $cnpa) or die(mysql_error());
$row_forum = mysql_fetch_assoc($forum);
$totalRows_forum = mysql_num_rows($forum);

?>
my other columns that i need are : name, date, question, reply, reply_name, reply_date

if u want more code....ill give u everything....but i guess this part is the important one
grudz
Forum Commoner
Posts: 68
Joined: Thu Dec 04, 2003 12:52 pm

Post by grudz »

whats weird is that it does sort it by date (in descending order) so it sort of "rocognizes" the other columns...but when i echo it.....i dont see anything
Post Reply