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 > help with GROUP BY

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-02-05, 08:22
hessodreamy hessodreamy is offline
Registered User
 
Join Date: Mar 2005
Posts: 16
help with GROUP BY

I have a table of customer problems, and another table of cummunications relating to the problem.

I'm trying to pull out for each problem: details of the problem, the most recent comversation, and the timestamp of the oldest conversation.

I've got the latest conversation like so:
Code:
select * from
tProblems p 
INNER JOIN 
(
SELECT * FROM tProblemComments order BY uts desc
) as pc ON p.poNumber = pc.poNumber
WHERE open = 1
group by p.poNumber
order by p.poNumber asc
Though this probably isn't the best way forward to proper solution, and I can't think how to do it.

Any ideas?

Heres the ddl:
Code:
CREATE TABLE `tproblems` (
  `poNumber` bigint(20) NOT NULL default '0',
  `contact` varchar(100) NOT NULL default '',
  `phone` varchar(100) NOT NULL default '',
  `open` tinyint(4) default NULL,
  PRIMARY KEY  (`poNumber`),
  KEY `closed` (`open`)
) 

CREATE TABLE `tproblemcomments` (
  `uts` int(11) NOT NULL default '0',
  `poNumber` int(11) NOT NULL default '0',
  `relevance` varchar(100) NOT NULL default '',
  `comment` text NOT NULL,
  `staff` varchar(20) NOT NULL default '',
  KEY `uts` (`uts`),
  KEY `poNumber` (`poNumber`)
)
Reply With Quote
  #2 (permalink)  
Old 12-09-05, 09:53
msueper msueper is offline
Registered User
 
Join Date: Feb 2005
Location: Germany
Posts: 22
the order by in the subquery is not necessare i guess:

select * from
tProblems p
INNER JOIN
tProblemComments as pc
ON p.poNumber = pc.poNumber
WHERE open = 1
group by p.poNumber
order by p.poNumber asc
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