close ad
WARNING PC USERS: Do Not Install the DREAMWEAVER CC 2017 Update »
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

Quick SQL question

Thread began 12/18/2014 11:22 am by iain331081 | Last modified 12/19/2014 11:18 am by Jason Byrnes | 546 views | 7 replies |

iain331081

Quick SQL question

I have a table of nominations for lodges that includes a Year field. Any given lodge can be nominated in different years, so will multiple records in this table, e.g.

LodgeID, Year
1, 2015
1, 2014
1, 2013
2, 2015
3, 2015
3, 2013

What would the SQL syntax be to return a list of lodges where the Year included 2015 only?

ie

2, 2015

Thanks.

Sign in to reply to this post

Jason ByrnesWebAssist

SELECT * FROM tableName WHERE Year = '2015'

Sign in to reply to this post

iain331081

Sorry, I could probably have worded that better.

I mean return lodges where the year = 2015 only, i.e. include:

2, 2015

Because 2015 is the only year that lodge had a nomination.

But exclude:

1, 2015
3, 2015

Because lodges 1 and 3 also had nominations in years other than 2015.

Sign in to reply to this post

Jason ByrnesWebAssist

SELECT * FROM tableName GROUP BY LodgeID HAVING COUNT(LodgeID) = 1

Sign in to reply to this post

iain331081

How does that reference lodges that were only nominated in 2015?

I tried using CASE:

SELECT LodgeID, Year FROM nominations GROUP BY LodgeID HAVING COUNT(CASE WHEN Year = '2015') = 1

But getting an error.

Sign in to reply to this post

Jason ByrnesWebAssist

SELECT * FROM testing GROUP BY LodgeID HAVING COUNT(LodgeID) = 1 AND Year = '2015'

Sign in to reply to this post

iain331081

Thanks Jason - that's working perfectly.

Sign in to reply to this post

Jason ByrnesWebAssist

you're welcome.

Sign in to reply to this post

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...