mysql bug or sql code error?

wxdqz

New Member
Hello,

I have a table called article and article_page. Basically articles consists of fields that store the article's name, date, author, etc. and the article_page table contains a page number, the article it relates to and the text of the page. Pretty simple stuff.

So picture the article page table containing this data.

articleId pageNumber text
--------- ---------- ----
1 1 'Page One'
1 2 'Page Two'

Now I want to make a function that finds the first page. Since I'm adding the functionality to delete pages, page 1 may not necessarily be the first page (I don't renumber the pages after a deletion). I use the following SQL code

SELECT articleId, MIN( pageNumber ), text
FROM article_page
WHERE articleId = 1
GROUP BY articleId

and the result returned is:

articleId = 1
articlePage = 1
text = 'Page Two'

Can anyone tell me why? This doesn't make any sense, especially that I don't don't have any joins.

The weird thing is, this only happens if I delete the article and its corresponding pages afterwards. If I leave it there and do the same exact thing for another article (with articleId = 2), then when I do the exact same SQL query, it'll work properly. I'm using excellent coding practices and proper layering. I've been doing this forever actually and this has been the weirdest thing I've ever seen. Right when I query the database (not applying any transformations whatsoever), it gives those wrong results.

Any answers? Thanks in advance for any help that you could provide me as I've looked at this for a long time.
 
Back
Top