1

I have an attribute table that shows states, years, and other specific things of that state in that year. How do I create an expression (so I can export a shapefile with these selected features) that:

  • Selects a state
  • Selects only the years 1995-2000 of that state

"st" = 'CA' AND "yr" = '1995' AND "yr" = '1996' etc.

does not work...


Solution:

"st" = 'CA' AND "yr" = '1995' OR "yr" = '1996' OR "yr" = '1997'

3
  • Put quotation marks missing. "st" = 'CA' AND "yr" = '1995' AND "yr" = '1996' etc. – Fran Raga Jul 17 '16 at 17:55
  • Thanks for catching my mistake in my post, Francisco! I should have just copied and pasted what I actually had typed inside QGIS. Unfortunately even when the proper quotation marks are added this doesn't display any results (0). "st" = 'CA' AND "yr" = '1995' AND "yr" = '1996' AND "yr" = '1997' – DudeNamedLuigi Jul 17 '16 at 18:05
  • put "st" = 'CA' AND "yr" = '1995' OR "yr" = '1996' OR "yr" = '1997' – Fran Raga Jul 17 '16 at 18:30
2

To select different years you need to use OR rather than AND between your years.

"st" = 'CA' AND "yr" = '1995' OR "yr" = '1996'

Using AND tells it to select each individual record that has a year 1995 AND 1996 AND 1997 etc., where each record only has a single year against it.

2
  • I don't know QGIS, but there may be better ways to do the selection, such as "st" = 'CA' AND "yr" IN ('1995', '1996', '1997') which would select any records where ST is CA and the Year is at one of the values in the list – Midavalo Jul 17 '16 at 18:37
  • I'm going to try that right now because it would be easier in the future for similar projects, but your first suggestion definitely works for me too. – DudeNamedLuigi Jul 17 '16 at 18:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.