Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Subquery problem

Status
Not open for further replies.

voomboom

Programmer
Jan 1, 2006
3
GB
Hi

I trying to use a simple subquery to find out the highest primary key in a table and print all of the results other than that one, but I keep getting a syntax error related to the subquery and I have no Idea why...

Does anybody know what I'm doing wrong?

Here is the code:

SELECT *
FROM sm_articles
WHERE articles_pk < (SELECT MAX(articles_pk) FROM sm_articles)

the table has 4 columns which are; articles_pk, articles_title, articles_date, articles_text.

Many thanks
 
Insufficient data for a meaningful answer.

Does MySQL return an error? If so, what error?

Are you running a version of MySQL that supports subqueries (i.e. version 4.1 or higher)?

Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Hi

Sorry about that. The Error I get is this:

_____________________________________

SQL-query:

SELECT *
FROM sm_articles
WHERE articles_pk < (
SELECT MAX( articles_pk )
FROM sm_articles )
MySQL said:

#1064 - You have an error in your SQL syntax near 'SELECT MAX(articles_pk) FROM sm_articles)' at line 3

______________________________________

I am using MySQL 5.0, building a PHP website, but I get this error in phpMyAdmin and a similar error in Dreamweaver MX
 
i know you said you're using 5.0, but are you sure? that error message is exactly what you'd get if you ran the query in 4.0

run this query to confirm:
Code:
select version() as v

r937.com | rudy.ca
 
Big thanks for getting me to double check the version.

I did have version 5.0 installed on my PC, but I was connecting to 4.0.

Anyway, got it working now

Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top