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 > Mysql Order

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-21-09, 20:26
shivam0101 shivam0101 is offline
Registered User
 
Join Date: Dec 2009
Posts: 6
Mysql Order

CREATE TABLE `hits` (
`hit_id` int(11) NOT NULL auto_increment,
`hit_date` datetime NOT NULL,
`hit_ip` varchar(15) NOT NULL,
PRIMARY KEY (`hit_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ;


I need all unique ip address datewise in descending order,
SELECT * FROM `hits` GROUP BY `hit_ip` ORDER BY `hit_date` DESC

expected,
hit_id hit_date hit_ip
3 2009-12-24 16:08:55 1.1.1.2
2 2009-12-22 16:08:38 1.1.1.1

i am getting,
hit_id hit_date hit_ip
3 2009-12-24 16:08:55 1.1.1.2
1 2009-12-21 16:07:54 1.1.1.1
Reply With Quote
  #2 (permalink)  
Old 12-21-09, 23:22
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
Quote:
Originally Posted by shivam0101 View Post
I need all unique ip address datewise in descending order
if each ip address can have multiple dates, then "unique ... datewise" doesn't make sense

it ~is~ possible, however, to associate a single date with each ip address -- the earliest, the latest, or some other calculation

what did you have in mind for this?
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 12-22-09, 08:04
shivam0101 shivam0101 is offline
Registered User
 
Join Date: Dec 2009
Posts: 6
I want to display ip addresses when they last visited. That's the reason i want all the unique ip address and the dates in ascending order.
Reply With Quote
  #4 (permalink)  
Old 12-22-09, 08:10
shivam0101 shivam0101 is offline
Registered User
 
Join Date: Dec 2009
Posts: 6
I want to display ip addresses when they last visited. That's the reason i want all the unique ip address and the dates in ascending order.
Reply With Quote
  #5 (permalink)  
Old 12-22-09, 08:17
shivam0101 shivam0101 is offline
Registered User
 
Join Date: Dec 2009
Posts: 6
I want to display ip addresses when they last visited. That's the reason i want all the unique ip address and the dates in ascending order.
Reply With Quote
  #6 (permalink)  
Old 12-22-09, 09:26
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
Code:
SELECT hit_ip 
     , MAX(hit_date) AS last_visit
  FROM hits 
GROUP 
    BY hit_ip 
ORDER 
   BY last_visit DESC
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #7 (permalink)  
Old 12-22-09, 09:40
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
Code:
SELECT hit_ip 
     , MAX(hit_date) AS last_visit
  FROM hits 
GROUP 
    BY hit_ip 
ORDER 
   BY last_visit DESC
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #8 (permalink)  
Old 12-22-09, 09:46
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
Code:
SELECT hit_ip 
     , MAX(hit_date) AS last_visit
  FROM hits 
GROUP 
    BY hit_ip 
ORDER 
   BY last_visit DESC
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
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