hosted by liquidweb


Go Back   Web Hosting Talk : Web Hosting Main Forums : Programming Discussion : MySQL Query : Know the "Z" next entry
Reply

Programming Discussion Discussions related to web programming languages and other related issues. Topics may include configuration, optimization, practical usage and database connectivity.
Forum Jump

MySQL Query : Know the "Z" next entry

Reply Post New Thread In Programming Discussion Subscription
 
Send news tip View All Posts Thread Tools Search this Thread Display Modes
  #1  
Old 07-07-2010, 06:15 PM
excessnet excessnet is offline
Junior Guru
 
Join Date: Aug 2006
Location: Quebec, Canada
Posts: 215

MySQL Query : Know the "Z" next entry


If I have, for exemple :
pid : 4, 24, 28, 39, 48, 59, 72

and I want to ask MySQL "from PID 24, what is the PID of the 3 next ?" and he will tell me "48"

How can I do this ?

I need to do this for something WAY bigger... more like "from PID 210589, show me the PID for the entry 100 000 later"

__________________
nka

http://forums.quebecit.net - Besoin d'aide en informatique gratuite ?
http://www.quebecit.net - Besoin d'hebergerment pour votre site internet ?

Reply With Quote


Sponsored Links
  #2  
Old 07-07-2010, 06:56 PM
Steve_Arm Steve_Arm is offline
Community Guide
 
Join Date: Jan 2006
Location: Athens, Greece
Posts: 1,479
You want to select a record that is after 210589 and 100000 rows after.

"SELECT pid FROM table WHERE pid > 210589 LIMIT 100000,1"

__________________


Reply With Quote
  #3  
Old 07-08-2010, 12:24 AM
tim2718281 tim2718281 is offline
Web Hosting Master
 
Join Date: Mar 2009
Posts: 2,218
Quote:
Originally Posted by excessnet View Post
If I have, for exemple :
pid : 4, 24, 28, 39, 48, 59, 72

and I want to ask MySQL "from PID 24, what is the PID of the 3 next ?" and he will tell me "48"

How can I do this ?

I need to do this for something WAY bigger... more like "from PID 210589, show me the PID for the entry 100 000 later"
What do you mean by "100 000 later"?

Are you assuming rows will be retrieved in some particular order?

If you want to retrieve rows in order of PID, you can used the ORDER BY clause, then use LIMIT to restrict the rows retrieved after sorting.

But if you want to retrieve rows in order of insertion, you need to include a column giving the insertion order and specify that column in the ORDER BY clause.

Reply With Quote
Sponsored Links
  #4  
Old 07-08-2010, 10:18 AM
excessnet excessnet is offline
Junior Guru
 
Join Date: Aug 2006
Location: Quebec, Canada
Posts: 215
Quote:
Originally Posted by Steve_Arm View Post
You want to select a record that is after 210589 and 100000 rows after.

"SELECT pid FROM table WHERE pid > 210589 LIMIT 100000,1"
working, thanks!

__________________
nka

http://forums.quebecit.net - Besoin d'aide en informatique gratuite ?
http://www.quebecit.net - Besoin d'hebergerment pour votre site internet ?

Reply With Quote
Reply

Similar Threads
Thread Thread Starter Forum Replies Last Post
"Can't connect to local MySQL server" + "IPS Driver Error" Bashaar Hosting Security and Technology 3 06-05-2007 02:22 AM
Every day after upcp "apache_LISTSUBDOMAINS_0:" and "DBD::mysql::st execute failed" germanos Hosting Security and Technology 0 10-01-2006 11:27 AM
Setting up MYSQL Server - Which DB Usage role? "Multifunctional" or "Transactional"?? Tuan Le Hosting Security and Technology 3 03-25-2006 11:21 AM
Setting up MYSQL Server - Which DB Usage role? "Multifunctional" or "Transactional"?? Tuan Le Ecommerce Hosting & Discussion 0 03-24-2006 07:10 PM
Seeing "test" and "test_supp" mysql dbs in phpmyadmin suhailc Hosting Security and Technology 1 04-15-2005 08:22 PM

Related posts from TheWhir.com
Title Type Date Posted
Web Host Rackspace Launches Private Beta for MySQL Cloud Database Web Hosting News 2011-12-01 21:09:51
Parallels Now Offering Licenses for CloudLinux OS Web Hosting News 2011-10-26 17:29:25
Web Hosting Software Firm CloudLinux Releases CloudLinux OS Version 6.1 Web Hosting News 2011-09-13 14:08:49
Web Hosting Sales and Promos Roundup - September 9, 2011 Web Hosting News 2011-09-09 19:57:57
Web Host FireHost Partners with Cloud Security Firm Gazzang for Data Encryption Web Hosting News 2011-08-16 20:33:43


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes
Postbit Selector

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump
Login:
Log in with your username and password
Username:
Password:



Forgot Password?
Advertisement:
Web Hosting News:



 

X

Welcome to WebHostingTalk.com

Create your username to jump into the discussion!

WebHostingTalk.com is the largest, most influentual web hosting community on the Internet. Join us by filling in the form below.


(4 digit year)

Already a member?