Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > MySQL
| Search | Today's Posts | Mark Forums Read
MySQL General discussion about the MySQL database.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the MySQL section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 17th, 2003, 04:07 AM
Registered User
 
Join Date: Sep 2003
Location: , , .
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default MySQL query desc order problem

Suppose my MySQL database has 50 records and my query is as:

select distinct(l.sno), c1.cname source, c2.cname dest, c3.cname protocol, l.dest_port
from Log l, Objects o1, Component c1, Objects o2, Component c2, Services s, Component c3
where ((l.source_ip=o1.objlowip) and (c1.cid=o1.objid))
and ((l.dest_ip=o2.objlowip) and (c2.cid=o2.objid))
and (((l.dest_port=s.supp && slowp) and (l.protocol=s.protocol)) and (s.sid=c3.cid))
order by sno desc limit 2,10;

It will display the 10 records starting from last and leaving last 2. But if I want to display 10 records before sno=48 i.e. by specifying sno in my query. How can I modify my query i.e. how can I specify sno.



 
Old September 17th, 2003, 11:41 AM
Friend of Wrox
Points: 2,570, Level: 21
Points: 2,570, Level: 21 Points: 2,570, Level: 21 Points: 2,570, Level: 21
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: San Diego, CA, USA
Posts: 836
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Have you tried using a (sno < 48) in your where clause?


Take care,

Nik
http://www.bigaction.org/
 
Old September 17th, 2003, 11:14 PM
Registered User
 
Join Date: Sep 2003
Location: , , .
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Sir,
Ur query i.e. by applying sno<48 gives bulk values and also it does not correctly apply order by clause.
Thanx

 
Old September 18th, 2003, 01:11 AM
Friend of Wrox
Points: 2,570, Level: 21
Points: 2,570, Level: 21 Points: 2,570, Level: 21 Points: 2,570, Level: 21
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: San Diego, CA, USA
Posts: 836
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I'm not quite sure I follow what you mean... you're linking all the tables (l, s, c1, and c2) by various columns, so limiting the rows from l where l.sno < 48 should just reduce the final result set returned after linking all the remaining rows. The ORDER BY clause sorts the final results of a query, and said sorting should really be done after that final result set is determined; i.e. AFTER the (l.sno < 48) row filter is applied.

So, i guess my question to you is, what query did you try, exactly, and what was wrong with your results?

If you need further assistance, perhaps you can dump the structure and contents of your tables, and perhaps give a more detailed description of the result set you want so that we can figure out your query.


Take care,

Nik
http://www.bigaction.org/




Similar Threads
Thread Thread Starter Forum Replies Last Post
Order by Desc Access 2007 mateenmohd Access 2 June 10th, 2008 09:11 AM
ASP/MySQL Order by problem lubany Classic ASP Databases 6 August 15th, 2006 12:52 PM
Descending order Query problem dssachdeva SQL Language 1 September 17th, 2003 11:44 AM
Desc order problem dssachdeva Oracle 0 September 17th, 2003 04:42 AM
Err Desc: Operation must use an updateable query vincentc Access ASP 1 September 3rd, 2003 02:38 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.