Results 1 to 8 of 8

Thread: Mysql Order

  1. #1
    Join Date
    Dec 2009
    Posts
    7

    Unanswered: 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

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    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?
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Dec 2009
    Posts
    7
    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.

  4. #4
    Join Date
    Dec 2009
    Posts
    7
    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.

  5. #5
    Join Date
    Dec 2009
    Posts
    7
    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.

  6. #6
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Code:
    SELECT hit_ip 
         , MAX(hit_date) AS last_visit
      FROM hits 
    GROUP 
        BY hit_ip 
    ORDER 
       BY last_visit DESC
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  7. #7
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Code:
    SELECT hit_ip 
         , MAX(hit_date) AS last_visit
      FROM hits 
    GROUP 
        BY hit_ip 
    ORDER 
       BY last_visit DESC
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  8. #8
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Code:
    SELECT hit_ip 
         , MAX(hit_date) AS last_visit
      FROM hits 
    GROUP 
        BY hit_ip 
    ORDER 
       BY last_visit DESC
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •