Current location: Hot Scripts Forums » Other Discussions » Database » Selecting only the second entry of a table


Selecting only the second entry of a table

Reply
  #1 (permalink)  
Old 06-19-07, 02:05 AM
anarchoi anarchoi is offline
Newbie Coder
 
Join Date: Nov 2006
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
Spin Selecting only the second entry of a table

just one stupid question : how can i select only the SECOND entry of a table?

with LIMIT, 2 it would display the first and the second
__________________
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 06-19-07, 02:44 AM
UnrealEd's Avatar
UnrealEd UnrealEd is offline
Community Liaison
 
Join Date: May 2005
Location: Antwerp, Belgium
Posts: 3,165
Thanks: 4
Thanked 25 Times in 25 Posts
SQL Code:
  1. SELECT * FROM mytable LIMIT 1, 2
You just have to define the offset: 0 means "beginning of the table", and 1 means starting from the second row. It goes on for 3,4,5,...
__________________
"Good judgement comes from experience, and experience comes from bad judgement." - Fred Brooks

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 06-19-07, 04:44 AM
anarchoi anarchoi is offline
Newbie Coder
 
Join Date: Nov 2006
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
this display the first AND the second entry unless i'm doing something wrong

i want just the second entry
__________________
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 06-19-07, 05:33 AM
UnrealEd's Avatar
UnrealEd UnrealEd is offline
Community Liaison
 
Join Date: May 2005
Location: Antwerp, Belgium
Posts: 3,165
Thanks: 4
Thanked 25 Times in 25 Posts
this should display the second and third row. If you just replace the 2 by 1, it will display the second row:
SQL Code:
  1. SELECT * FROM mytable LIMIT 1, 1
i tested it on my server when i posted the code in my previous code, and it worked just fine. Anyway, you should be able to fix it yourself:
the first number defines the offset of the query
the last number defines the length of the returned result

more information: http://dev.mysql.com/doc/refman/5.0/...html#id3093998
__________________
"Good judgement comes from experience, and experience comes from bad judgement." - Fred Brooks

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #5 (permalink)  
Old 06-19-07, 03:15 PM
Sxooter Sxooter is offline
Newbie Coder
 
Join Date: Jun 2007
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Note that most later version of mysql allow the limit / offet syntax, which is much more clear.

select * from sometable order by somefield limit 1 offset 1

(offset 0 would get you the first row)

pgsql dropped support for the limit x,y syntax some time ago because theirs was limit,offset while mysql was offset,limit and it lead to a lot of confusion. both dbs support offset x limit y syntax, so I tend to use that more often because it's both more readable and portable.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
MYSQL database countll Database 2 06-19-07 05:20 PM
What do you think of my database structure? Oskare100 Database 5 12-27-06 08:43 AM
Pretty simple ( i think) question any help!?!? 0o0o0 PHP 2 04-07-06 11:47 AM
PHP: Different table entry from same form? Stormrider Script Requests 3 05-07-05 09:19 AM
Deleting one entry on dynamic table Bonzo PHP 1 04-19-04 03:36 PM


All times are GMT -5. The time now is 12:31 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.