SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    Patience... bronze trophy solidcodes's Avatar
    Join Date
    Jul 2006
    Location
    Philippines
    Posts
    936
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)

    Conditional SELECT?

    How to SELECT this in MySQL,

    Table structure
    Code:
    lessonid | classid |
    --------------------
    1   	 | 4
    2   	 | 4
    5   	 | 5
    6   	 | 5
    7   	 | 7
    11  	 | 7	 
    12  	 | 7
    From the table structure above, How to select classid's that has the lowest number of lessonid only?
    So the result above should look like this below,
    Code:
    lessonid | classid |
    --------------------
    1   	 | 4
    5   	 | 5
    7   	 | 7
    By the way lessonid is the primary key.

    Thanks in advance.
    Quality codes are optimized and tested...
    Click here for inspiration..

  2. #2
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2006
    Location
    Augusta, Georgia, United States
    Posts
    4,182
    Mentioned
    16 Post(s)
    Tagged
    4 Thread(s)
    SELECT MIN(lessonid) minlessonid, classid FROM thetable GROUP BY classid ORDER BY minlessonid ASC;
    The only code I hate more than my own is everyone else's.

  3. #3
    Patience... bronze trophy solidcodes's Avatar
    Join Date
    Jul 2006
    Location
    Philippines
    Posts
    936
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    @oddz ;
    Thanks dude, I will try that later.
    Quality codes are optimized and tested...
    Click here for inspiration..


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
  •