Results 1 to 2 of 2
  1. #1
    Join Date
    Dec 2011
    Posts
    16

    Unanswered: nested select not working?

    I have a table 'mytable' with two columns, 'name' and 'value'.
    I want to select all 'name' of rows whose value = max(value)

    We can do it without a nested select, like this:
    SELECT MAX(value) FROM mytable
    store this value in PHP as $max_value
    then do,
    SELECT name FROM mytable WHERE value = '$max_value'

    But when I tried to do a nested select, it failed. I've tried:
    SELECT name
    FROM mytable
    WHERE value = (SELECT MAX(value) FROM mytable);

    SELECT name
    FROM myTable
    WHERE value IN (SELECT max(value) FROM myTable)

    Both failed to retrieve any rows. Any ideas?

    The MySQL version is 5.1.58.

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Quote Originally Posted by hello-world View Post
    Both failed to retrieve any rows. Any ideas?
    not unless we can see the real query
    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
  •