Presentation is loading. Please wait.

Presentation is loading. Please wait.

Mastering ArcGIS Chapter 7 Queries.

Similar presentations


Presentation on theme: "Mastering ArcGIS Chapter 7 Queries."— Presentation transcript:

1 Mastering ArcGIS Chapter 7 Queries

2 What are queries? Extract certain records from a map or table
Mastering ArcGIS Chapter 7 What are queries? Extract certain records from a map or table Records meet certain criteria Aspatial queries All parcels with value greater than $100,000 Spatial queries All parcels that lie completely within the flood plain Copyright © 2009 by Maribeth H. Price

3 SELECT *FROM FIELD WHERE
Mastering ArcGIS Chapter 7 SQL Many databases use a special query language called Structured Query Language SELECT *FROM FIELD WHERE Copyright © 2009 by Maribeth H. Price 3

4 Mastering ArcGIS Chapter 7 SQL Query Examples Some Valid Queries SELECT *FROM cities WHERE "POP1990" >= SELECT *FROM counties WHERE “BEEFCOW_92” < “BEEFCOW_87” SELECT *FROM parcels WHERE “LU- CODE” = 42 AND “VALUE” > 50000 SELECT *FROM rentals WHERE “RENT” > 700 AND “RENT” < 1500 Programs may have an interface to help users build SQL expressions In most databases, SQL expressions are case-sensitive “Smith” ≠ “SMITH” Copyright © 2009 by Maribeth H. Price 4

5 Single criteria T A B Select students from T where [Home_State] = “NY”
Mastering ArcGIS Chapter 7 Single criteria Let T = [all students in University] Let A = [students from New York] Let B = [Geography majors] Let C = [English majors] T A B Select students from T where [Home_State] = “NY” Select students from T where [Major] = “Geography” Copyright © 2009 by Maribeth H. Price 5

6 Mastering ArcGIS Chapter 7 Queries as sets Let T = [all students in University] Let A = [students from New York] Let B = [Geography majors] Let C = [English majors] T A Queries are used to extract subsets (records) of interest from a set (table) Multiple criteria may be used (such as Geography majors from New York) B C Copyright © 2009 by Maribeth H. Price 6

7 Mastering ArcGIS Chapter 7 Double criteria T Let T = [all students in University] Let A = [students from New York] Let B = [Geography majors] Let C = [English majors] A B Select students from T where [Home_State] = “NY” OR [Home_State] = “NJ” Select students from T where [Home_State] = “NY” AND [Major] = “Geography” Copyright © 2009 by Maribeth H. Price 7

8 Mastering ArcGIS Chapter 7 AND vs OR? T A B C Let T = [all students in University] Let A = [students from New York] Let B = [Geography majors] Let C = [English majors] Select students from T where [Home_State] = “NY” OR [Home_State] = “NJ” Select students from T where [Home_State] = “NY” AND [Major] = “Geography” Each condition is tested separately. If AND is used, then BOTH must be true. If OR is used, then either may be true. Copyright © 2009 by Maribeth H. Price 8

9 Boolean expressions AND and OR are Boolean operators
Mastering ArcGIS Chapter 7 Boolean expressions AND and OR are Boolean operators Boolean operators are used to evaluate pairs of conditions Copyright © 2009 by Maribeth H. Price 9

10 Mastering ArcGIS Chapter 7 AND vs OR? T A B C Let T = [all students in University] Let A = [students from New York] Let B = [Geography majors] Let C = [English majors] A AND B A B Select students from T where [Home_State] = “NY” AND [Major] = “Geography” Copyright © 2009 by Maribeth H. Price 10

11 Mastering ArcGIS Chapter 7 AND vs OR? T A B C Let T = [all students in University] Let A = [students from New York] Let B = [Geography majors] Let C = [English majors] A OR B A B Select students from T where [Home_State] = “NY” OR [Major] = “Geography” Copyright © 2009 by Maribeth H. Price 11

12 Mastering ArcGIS Chapter 7 What do you get? T A B C Select students from T where [Major] = “Geography” OR [Major] = “English” B OR C Select students from T where [State] = “NY” AND [Major] = “English” A AND C Select students from T where [State = “NY” OR [Major] = “English” A OR C Let T = [all students in University] Let A = [students from New York] Let B = [Geography majors] Let C = [English majors] Copyright © 2009 by Maribeth H. Price 12

13 Mastering ArcGIS Chapter 7 What do you get? T A B C Select students from T where [Major] = “Geography” AND [Major] = English” B AND C Select students from T where [AGE] > 20 AND [AGE] < 30 ? AND ? Select students from T where [AGE] > 20 OR [AGE] < 30 ? OR ? Let T = [all students in University] Let A = [students from New York] Let B = [AGE > 30] Let C = [AGE < 20] Copyright © 2009 by Maribeth H. Price 13

14 Other Boolean operators
Mastering ArcGIS Chapter 7 Other Boolean operators Some databases use additional operators besides AND and OR A AND B A XOR B A NOT B A OR B A B Copyright © 2009 by Maribeth H. Price 14

15 What do you get? T A B C A AND B A OR B A XOR B A NOT B B AND A B OR A
Mastering ArcGIS What do you get? Chapter 7 T A B C A AND B A OR B A XOR B A NOT B B AND A B OR A B XOR A B NOT A Let T = [all students in University] Let A = [students from New York] Let B = [Geography majors] Let C = [English majors] Copyright © 2009 by Maribeth H. Price 15

16 Remember—you test each feature separately
Mastering ArcGIS Chapter 7 Test: AND vs OR Remember—you test each feature separately Wrong Right “Land-use” = ‘RES’ AND “Land-use” = ‘COM’ “Land-use” = ‘RES’ OR “Land-use” = ‘COM’ “Pop2000” ≥ 5000 OR “Pop2000” < 9000 “Pop2000” ≥ 5000 AND “Pop2000” < 9000 Copyright © 2009 by Maribeth H. Price 16

17 Order of operations Boolean operators have equal order or precedence
Mastering ArcGIS Chapter 7 Order of operations Boolean operators have equal order or precedence Evaluation occurs from left to right Parentheses must be used to change order Copyright © 2009 by Maribeth H. Price 17

18 What do you get? T A B C A AND B OR C ( A AND B ) OR C A AND (B OR C)
Mastering ArcGIS Chapter 7 What do you get? T A B C A AND B OR C ( A AND B ) OR C A AND (B OR C) (A OR B ) AND C A OR (B AND C) A AND B A XOR B A NOT B A OR B A B Let T = [all students in University] Let A = [students from New York] Let B = [Geography majors] Let C = [English majors] Copyright © 2009 by Maribeth H. Price 18

19 Multiple conditions Test using these parcels RES COM $75,000 $75,000
Mastering ArcGIS Chapter 7 Multiple conditions Test using these parcels $75,000 $75,000 $75,000 $75,000 $125,000 $125,000 $125,000 $125,000 RES COM Copyright © 2009 by Maribeth H. Price 19

20 (“LU” = ‘RES’ or “LU” = ‘COM’) and “Value” > 100000
Mastering ArcGIS Chapter 7 Multiple conditions Test using these parcels (“LU” = ‘RES’ or “LU” = ‘COM’) and “Value” > $75,000 $75,000 $75,000 $75,000 $125,000 $125,000 $125,000 $125,000 RES COM Copyright © 2009 by Maribeth H. Price 20

21 “LU” = ‘RES’ or (“LU” = ‘COM’ and “Value” > 100000)
Mastering ArcGIS Chapter 7 Multiple conditions Test using these parcels “LU” = ‘RES’ or (“LU” = ‘COM’ and “Value” > ) $75,000 $75,000 $75,000 $75,000 $125,000 $125,000 $125,000 $125,000 RES COM Copyright © 2009 by Maribeth H. Price 21


Download ppt "Mastering ArcGIS Chapter 7 Queries."

Similar presentations


Ads by Google