All times are UTC - 6 hours




Post new topic Reply to topic   Page 1 of 1
 [ 2 posts ] 
Author Message

 Post subject: MySQL Query help
PostPosted: November 16th, 2012, 8:20 am 
Sorceror of Saradomin
Sorceror of Saradomin
User avatar

Joined: November 8th, 2004, 7:15 am
Posts: 2,889
Location: In the Depths of the Forest
Gender: Male
Status: Offline

Donor: Prince (2009)
Hi guys, I have a problem I can't work out at the moment and I was wondering if someone here could help me. Basically I have a table that has only two columns, ID and Year. I need to select all the IDs from the table where the ID appears in consecutive years.

So with this sample data:

ID | Year
------------------
1 | 2001
1 | 2002
2 | 2003
2 | 2005
3 | 2006
3 | 2007

I would want to extract 1 and 3. Does this make sense? I can't really think of any other way to describe it, but if you have any questions that could help out please let me know!

tru :wink:

__________________
Image
My DeviantART


Top
 Profile
 

 Post subject: Re: MySQL Query help
PostPosted: November 23rd, 2012, 11:44 am 
Sorceror of Saradomin
Sorceror of Saradomin
User avatar

Joined: August 28th, 2003, 3:25 am
Posts: 3,825
Location: Wales, UK
Gender: Male
Status: Offline
select a.id from `table` as a inner join `table` as b on a.`id` = b.`id` where a.`Year` +1 = b.`Year`


Should work

__________________
Image
Image


Top
 Profile WWW 
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  Page 1 of 1
 [ 2 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 14 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Jump to:  

Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
The Village and this web site are © 2002-2012

ThePub 2.0 - Designed by Goten & Jackstick. Coded by Glodenox & Henner.
With many thanks to the Website Team!