MYSQL query problem

Discussion in 'MySQL' started by TerriKat, May 27, 2008.

  1. #1
    I have a database Faculty_Artwork with the fields ID, Artwork, Faculty_ID, ArtTitle, ArtMedium, ArtSize, ArtYear, and ImageNo. It's set up so I can search according to Faculty_ID and I'm supposed to get nothing when there are no rows with that specific number in Faculty_ID. But when I run a query of a Faculty_ID that isn't in there, for example:

    SELECT max(ImageNo) FROM Faculty_Artwork WHERE Faculty_ID = 316

    I get a returned row with 316 assigned to ID and that's all that's in the query. Anyone know why I'm getting records at all?
     
    TerriKat, May 27, 2008 IP
  2. briteguy1227

    briteguy1227 Peon

    Messages:
    27
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I did a similar test with a database, and what I got is just null in the max(xxx) field.

    So, if in theory it works for you, it should just return null.
     
    briteguy1227, May 27, 2008 IP
  3. CreativeClans

    CreativeClans Peon

    Messages:
    128
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #3
    You can't get a value assigned to ID, since you aren't selecting the ID field. And if there's no Faculty_ID 316 in your table, then the value returned by the query should be NULL, just like briteguy1227 says.
    If you get a different result, it means the query you're testing isn't the one you posted here, or there's data in your database that meets the requirements of your WHERE statement.
     
    CreativeClans, May 28, 2008 IP
  4. ArcticPro

    ArcticPro Banned

    Messages:
    1,273
    Likes Received:
    30
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Doesn't make sense to get a result when you select.... strange!
     
    ArcticPro, May 28, 2008 IP
  5. sukosari

    sukosari Active Member

    Messages:
    63
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    93
    #5
    i have no idea, because when using MAX fuction the result should be one record
     
    sukosari, May 29, 2008 IP