Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.
Moderator: General Moderators
SpaceManSpiff
Forum Newbie
Posts: 6 Joined: Sat Apr 27, 2002 8:55 pm
Post
by SpaceManSpiff » Mon Apr 29, 2002 7:37 pm
I'm getting an error with the query below and I can't seem to find anything wrong with it. Can anyone help?
Code: Select all
SELECT NewsID,NewsTitle FROM News ORDER BY NewsDate LIMIT 3
Error Message:
Code: Select all
Error
SQL-query:
SELECT NewsID,NewsTitle FROM News ORDER BY NewsDate LIMIT 3
MySQL said:
It's weird because it doesn't even give a reason for the error after "MySQL said."
enygma
Site Admin
Posts: 175 Joined: Fri Apr 19, 2002 8:29 am
Location: Dallas, Tx
Post
by enygma » Mon Apr 29, 2002 10:34 pm
just be sure that everything is in the right case (MySQL is case sensitive), and, of course, obviously, that all the fields are there.
then, if that still doesn't work right, try running it on the command line MySQL client....and see what that says
-enygma
SpaceManSpiff
Forum Newbie
Posts: 6 Joined: Sat Apr 27, 2002 8:55 pm
Post
by SpaceManSpiff » Tue Apr 30, 2002 12:21 am
I tried using that query on phpMyAdmin, that's how I got that error message. All the cases are right and all the fields are there.
The query works fine when I take off "LIMIT 3." The problem occurs when I have that or "LIMIT 0, 3" at the end. Any ideas?
Oxy
Forum Newbie
Posts: 17 Joined: Fri Apr 19, 2002 5:47 am
Location: U.K
Contact:
Post
by Oxy » Tue Apr 30, 2002 5:21 am
Code: Select all
SELECT NewsID,NewsTitle FROM News ORDER BY NewsDate ASC LIMIT 3
try putting ASC/DESC in between NewsDate and LIMIT
SpaceManSpiff
Forum Newbie
Posts: 6 Joined: Sat Apr 27, 2002 8:55 pm
Post
by SpaceManSpiff » Tue Apr 30, 2002 7:48 pm
Oxy wrote: Code: Select all
SELECT NewsID,NewsTitle FROM News ORDER BY NewsDate ASC LIMIT 3
try putting ASC/DESC in between NewsDate and LIMIT
I don't understand what that would do, especially since it mixes up different clauses.. but since at this point I'm willing to try anything, it didn't work.
Code: Select all
Error
SQL-query:
SELECT NewsID,NewsTitle FROM News ORDER BY NewsDate LIMIT DESC 3
MySQL said: You have an error in your SQL syntax near 'DESC 3' at line 1
Is there any other way to get the three most recent records from a database? I know that in MSSQL, I can do.. "SELECT TOP 3 NewsID,NewsTitle FROM News ORDER BY NewsDate DESC"
Oxy
Forum Newbie
Posts: 17 Joined: Fri Apr 19, 2002 5:47 am
Location: U.K
Contact:
Post
by Oxy » Wed May 01, 2002 3:13 am
Code: Select all
SELECT * FROM News ORDER BY NewsDate DESC LIMIT 3
<edit>Fixed typo
Last edited by
Oxy on Wed May 01, 2002 2:37 pm, edited 1 time in total.
jason
Site Admin
Posts: 1767 Joined: Thu Apr 18, 2002 3:14 pm
Location: Montreal, CA
Contact:
Post
by jason » Wed May 01, 2002 6:21 am
Oxy, no..
Code: Select all
SELECT NewsID,NewsTitle FROM News ORDER BY NewsID DESC LIMIT 3
That is what you want.
jason
Site Admin
Posts: 1767 Joined: Thu Apr 18, 2002 3:14 pm
Location: Montreal, CA
Contact:
Post
by jason » Wed May 01, 2002 6:22 am
Also quick question.
Is there any data in the table?
Oxy
Forum Newbie
Posts: 17 Joined: Fri Apr 19, 2002 5:47 am
Location: U.K
Contact:
Post
by Oxy » Wed May 01, 2002 2:36 pm
yeah sorry typo, but i'm a bit confused as to why the first query I posted didn't work for you.
SpaceManSpiff
Forum Newbie
Posts: 6 Joined: Sat Apr 27, 2002 8:55 pm
Post
by SpaceManSpiff » Wed May 01, 2002 5:39 pm
jason wrote: Also quick question.
Is there any data in the table?
Yea, there's about five records in there, each having a different NewsDate.
phice
Moderator
Posts: 1416 Joined: Sat Apr 20, 2002 3:14 pm
Location: Dallas, TX
Contact:
Post
by phice » Wed May 01, 2002 11:57 pm
*sigh*
Code: Select all
SELECT * FROM News ORDER BY NewsID DESC LIMIT 0,3
then, just set $variable = $row['newsID']; or whatever.
EvilWalrus
Site Admin
Posts: 209 Joined: Thu Apr 18, 2002 3:21 pm
Location: Springmont, PA USA
Post
by EvilWalrus » Thu May 02, 2002 12:12 am
phice wrote: *sigh*
Code: Select all
SELECT * FROM News ORDER BY NewsID DESC LIMIT 0,3
then, just set $variable = $row['newsID']; or whatever.
'*' is evil