If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Group by and Order by

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-26-04, 00:36
pantof pantof is offline
Registered User
 
Join Date: Jul 2004
Posts: 1
Group by and Order by

I have a table like this

+-----------+---------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-----------+---------------------+------+-----+---------+----------------+
| id | int(3) | | PRI | NULL |
auto_increment |
| idTable | int(3) unsigned | | | 0 | |
| title | varchar(150) | YES | | NULL |
|
| description | varchar(150) | YES | | NULL | |
| date | datetime | YES | | NULL | |
+-----------+---------------------+------+-----+---------+----------------+

I want to make a select statement that show me the latest 10 rows from
this table without repetition on the idTable field, idTable is a foreing key from TableTest2, and I want that it just show me for
each idTable the latest row from TableTest2. I tried something like this:

SELECT TestTable.id, TestTable.idTable, TestTable.title, TestTable.description, TestTable.date, TestTable2.name FROM TestTable, TesteTable2 where TestTable.idTable = TestTable2.id GROUP BY TestTable.idTable ORDER BY date DESC;

But it didn't return the latest rows for each idTable.

could someone help me?
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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
Trackbacks are On
Pingbacks are On
Refbacks are On