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!

How to do ORDER BY and LIMIT to part of a select statement?

Status
Not open for further replies.

Zac5

Programmer
Jan 30, 2003
75
US
I want to perform 'order by' and 'limit' to part of my select statement, that is, only the part that meets the first condition, so i want to achieve following:

select * from page where (type=6 order by edate limit 1) or (date > (UNIX_TIMESTAMP-8400));

However this is not accepted - any suggestions please??

Many thanks!
 
( select * from page
where type=6
order by edate limit 1 )
union all
( select * from page
where date > (UNIX_TIMESTAMP-8400)

caution: untested


rudy
SQL Consulting
 
Didnt work - I dont think the version of MySQL I have supports UNION, I get an error.
 
well, you did not say which version you are on, so i felt it was only fair for me to use syntax from the current version

because you want only one of X but all of Y, you will have to use two queries

rudy
SQL Consulting
 
You are right. I'm sorry i didnt mention my version of mysql. I will use an alternative approach with the help of perl. Many thanks for your help.
 
Hi Zac5

You can create a query handle using syntax what MySql allows. And if your version does not allow UNION then you can try for the following suggested by r937 in another thread


[ponder]
----------------
ur feedback is a very welcome desire
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top