SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Thread: Subselects ?

  1. #1
    SitePoint Enthusiast
    Join Date
    May 2004
    Location
    uk
    Posts
    35
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Subselects ?

    Hello, can anyone tell me if subselects are allowed in MySQL - i am trying to do something like ...

    SELECT file_name,
    access_timestamp,
    (SELECT max(access_timestamp)
    FROM web_page_visitors w2
    WHERE w2.file_name = w1.file_name)
    FROM web_page_visitors w1
    WHERE access_timestamp >= (now() - INTERVAL 1 DAY )

    thanks

    steve

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,350
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    yes, in 4.1
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,350
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    prior to 4.1, try this:
    Code:
    select w1.file_name
         , w1.access_timestamp
         , max(w2.access_timestamp)
      from web_page_visitors w1
    left outer
      join web_page_visitors w2
        on w1.file_name 
         = w2.file_name
     where w1.access_timestamp 
        >= date_add(now(), interval -1 day ) 
    group
        by w1.file_name
         , w1.access_timestamp
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  4. #4
    SitePoint Enthusiast
    Join Date
    May 2004
    Location
    uk
    Posts
    35
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the help all

    i did it using a join - no worries !

    steve


Bookmarks

Posting Permissions

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