SitePoint Sponsor

User Tag List

Results 1 to 7 of 7

Hybrid View

  1. #1
    SitePoint Enthusiast
    Join Date
    Jan 2005
    Location
    marijampole
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    combining few select queries?

    hi, i searched a bit about this but can't seem to find a good answer
    anyways what i am trying to do is combine about 3 select queries that select one line each like first and last
    atm i got
    SELECT title , time FROM products WHERE title LIKE '%-$sets' ORDER BY `time` ASC LIMIT 0, 1
    SELECT title , time FROM products WHERE title LIKE '%-$sets' ORDER BY `time` DESC LIMIT 0, 1

    basically my quastion is there a way to combine them both ? it would save me a lot of work on tcl code part because i use something like this along about 5 separate scripts so it adds up

    any ideas/help appreciated or if you have any other performance hints i could use also appreciated

  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)
    what version of mysql?
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Enthusiast
    Join Date
    Jan 2005
    Location
    marijampole
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    atm 4.0.2 but upgrading soon to 5 probably so if you got anything for me shoot

  4. #4
    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)
    4.1 (subqueries) required --
    Code:
    select title 
         , time 
      from products 
     where title like '%-$sets' 
       and (
           time = (select min(time) from products)
        or time = (select max(time) from products)
           )
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  5. #5
    SitePoint Enthusiast
    Join Date
    Jan 2005
    Location
    marijampole
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    now that is getting complicated hehe tnks will have to look at it when i upgrade gonna bookmark this tnks a lot for this btw now is this performance wise is it any faster than just doing two separate queries ?

  6. #6
    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)
    faster? this depends on quite a number of factors

    why don't you test it and let us know?
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  7. #7
    SitePoint Enthusiast
    Join Date
    Jan 2005
    Location
    marijampole
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    will do when i upgrade hehe


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
  •