1 a trio of topics for confident access query writers elsug october 8, 2009 cathy salika carli
TRANSCRIPT
1
A Trio of Topics for Confident Access Query Writers
ELSUGOctober 8, 2009
Cathy SalikaCARLI
2
Three BIG Topics
Outer Joins
The BLOB Functions
Make Table Queries & Subqueries
3
Outer Joins
Most sources call them “outer joins”.
Access calls them “left joins” and “right joins”.
The distinction turns out to be not very helpful, at least to me.
4
Two reasons to use an outer join:
1) In case there are no matching data in a table you’re linking to
2) To find records that don’t have matching data in a table you’re linking to
5
In case there are no data in a table you’re linking to...What could go wrong with this query?
6
ITEMITEM_ID PRICE
1 $15.00
2 $180.69
ITEM_ID ITEM_BARCODE
1 309991234
3 309996789
ITEM_BARCODE
The normal join on ITEM_ID will give you just one record.
ITEM_ID PRICE ITEM_BARCODE
1 $15.00
309991234
Remember, you have to have matching ITEM_IDs in both tables to get a record.
7
So what could go wrong with this query?
Items with no barcode will not appear.
MFHDs with no item will not appear.
8
Think of some other examples where you might link to a table in which matching data might be missing.
A list of patrons, some of whom might not have barcodes
A list of purchase orders, some of which might not have invoices yet.
A list of items, some of which might not have statistical categories.
Others?
9
ITEMITEM_ID PRICE
1 $15.00
2 $180.69
ITEM_ID ITEM_BARCODE
1 309991234
3 309996789
ITEM_BARCODE
ITEM_ID PRICE ITEM_BARCODE
1 $15.00 309991234
2 $180.69
<Null>
How do we fix this? We change the join.
10
How’d she do that?
Right-click on the link...
... and select Join Properties
11
You get this...
12
Pick option 2, click OK, and the link turns into an arrow.
So what if I had picked option 3 instead?
13
The arrow would be pointing the other way.
This is the “left” and “right” aspect of joining, but since this...
... is just the same as the picture above, I don’t find “left” and “right” very helpful.
14
But it matters which table the arrow is pointing to!
A LOT!!!
15
ITEMITEM_ID PRICE
1 $15.00
2 $180.69
ITEM_ID ITEM_BARCODE
1 309991234
3 309996789
ITEM_BARCODE
ITEM_ID PRICE ITEM_BARCODE
1 $15.00 309991234
2 $180.69
<Null>
ITEM_ID PRICE ITEM_BARCODE
1 $15.00 309991234
3 <Null> 309996789
16
A list of items, some of which might not have statistical categories.
17
Moral: All the links beyond the arrow have to be arrows too.
18
A list of patrons, some of whom might not have barcodes
19
Two reasons to use an outer join:
1) In case there are no matching data in a table you’re linking to
2) To find records that don’t have matching data in the table you’re linking to
20
Suppose I want to find...
... the items that have no barcodes
... the bibs that have no holdings
... the patrons who have no barcodes
Use an outer join and check for the <Null> value.
The criterion is: Is Null
21
Items with no barcodes
22
Bibs with no holdings
23
Patrons with no barcodes
24
Any outer join questions?
25
What can you do now that you couldn’t do before you learned about outer joins?
26
Next topic: The BLOB Functions
27
Voyager stores catalog data in two ways:
Frequently used data are in their own fields.
Things like TITLE, AUTHOR, DISPLAY_CALL_NO
Fields that need to be indexed
Fields in multi-bib displays
The whole MARC record is stored as a Binary Large OBject.
The BLOB functions let you get at any piece of a MARC record.
28
The BLOB functions are indispensable, but they’re slow, so
Remember the Alternatives!
29
Alternatives to the BLOB Queries
For common fields, try BIB_TEXT
For fields in left-anchored indexes, try BIB_INDEX
For fixed fields, try MARC*_VW (e.g. MARCBOOK_VW)
For URLs, try ELINK_INDEX
30
BIB_TEXT p. 11, 14, 27, 33, 36The starred fields in this table are in UTF-8.If you need data from a bib record that are not available in BIB_TEXT, check to see if
they arein BIB_INDEX. Using BIB_INDEX and BIB_TEXT is more efficient than using the BLOB
functions.If you’re thinking of using begin_pub_date in a criterion, consider using the indexed
version of this field. It’s in the BIB_INDEX table, in the normal_heading field when
index_code=008D.<snip>Here’s how MARC tags map to fields in BIB_TEXT:Leader byte 5 record_statusLeader bytes 6-7 bib_formatLeader byte 17 encoding_level<snip>020 a isbn022 a issn024 a other_std_num027 a stdtech<snip>100 abcdkq author110 abcdgkn author111 acdegkn author245 abcfghknps title245 ab title_brief130 adfgklmnoprs uniform_title
31
There are just 7 BLOB functions to learn
GetAuthBlob
GetBibBlob
GetMFHDBlob
GetField GetFieldAll GetFieldRaw
GetSubField
32
GetAuthBlob(auth_id)
GetBibBlob(bib_id)
GetMFHDBlob(mfhd_id)
These three aren’t useful on their own. They ask Voyager for a MARC record. You use one of these as a building block for the other functions.
33
Your query should include at least one table in which the ID field is unique, for example:
GetBibBlob([BIB_TEXT].[BIB_ID])
GetBibBlob([BIB_MASTER].[BIB_ID])
GetAuthBlob([AUTH_MASTER].[AUTH_ID])
GetMFHDBlob([MFHD_MASTER].[MFHD_ID])
BTW, capitalization doesn’t matter.
34
You’ll wrap one of these
GetField
GetFieldAll
GetFieldRaw
around one of these
GetAuthBlob
GetBibBlob
GetMFHDBlob
35
GetField gives you a single occurrence of a MARC field
Syntax:
GetField(
One of the Blob functions
,A MARC tag
, Which one? )
Example: the first 505 field in a bib record
GetField(GetBibBlob([BIB_TEXT].[BIB_ID]),’505’,1)
Example: the first subject (6xx field) in a bib record:
GetField(GetBibBlob([BIB_TEXT].[BIB_ID]),’6’,1)
36
Example: the first 505 field in a bib record
GetField(GetBibBlob([BIB_TEXT].[BIB_ID]),’505’,1)
v. 1. Ancient Egypt through the Middle Ages -- v. 2. The Renaissance to the present.
Example: the first subject (6xx field) in a bib record:
GetField(GetBibBlob([BIB_TEXT].[BIB_ID]),’6’,1)
Latin poetry, Medieval and modern History and criticism
37
A Blob Function in a Query
38
Using Shift-F2 to Zoom
39
Zoom works with criteria too.
You can resize the font to improve readability.
40
GetFieldAll gives you all occurrences of a MARC field
Syntax:
GetFieldAll(
One of the Blob functions
,A MARC tag
)
Example: all of the 650 fields in a bib record
GetFieldAll(GetBibBlob([BIB_TEXT].[BIB_ID]),’650’)
Example: all of the 866s in a MFHD:
GetFieldAll(GetMFHDBlob([MFHD_ID]),’866’)
41
Example: all of the 650 fields in a bib record
GetFieldAll(GetBibBlob([BIB_TEXT].[BIB_ID]),’650’)
Job enrichment
Employees' representation in management
Personnel management
You might have to make the rows in Access taller to see them all, because they all appear in one cell.
42
Example: all of the 866s in a MFHD:
GetFieldAll(GetMFHDBlob([MFHD_MASTER].[MFHD_ID]),’866’)
0 no.1 (1958)-no. 6 (1962)
0 no. 8 (1964)-no. 11 (1966)
0 no. 16 (1968)-no. 18 (1973-1975)
43
“Advanced Features” for GetField and GetFieldAll
You may add 2 more parameters to these functions
* a list of subfields that you want to see
* a separator to appear between subfields
44
GetField(GetBibBlob([BIB_TEXT].[BIB_ID]),”650”)Forensic psychiatry Illinois Bloomington Case
studies.
Example: the first 650 field, subfields a and xGetField(GetBibBlob([BIB_TEXT].[BIB_ID]),”650”,1,”ax”)
Forensic psychiatry Case studies.
Example: the first 650 field, subfields a, x and z with double dashes between subfields
GetField(GetBibBlob([BIB_TEXT].[BIB_ID]),”650”,1,”axz”,”--”)
Forensic psychiatry--Case studies--Illinois--Bloomington.
45
GetFieldRaw give you one occurrence of a MARC field, including the tag, indicators, and subfield coding.
* It’s the only way to get the indicators.
* It’s the only function that works with GetSubField.
Syntax:
GetFieldRaw(
One of the Blob functions
,A MARC tag
Which one?
),
Example: the third 650 field in a bib record:
GetFieldRaw(GetBibBlob([BIB_TEXT].[BIB_ID]),’650’,3)
46
Example: the third 650 field in a bib record:
GetFieldRaw(GetBibBlob([BIB_TEXT].[BIB_ID]),’650’,3)
650 0aDay care centersxGovernment policyzUnited States.
47
245: getfieldraw(getbibblob([bib_text].[bib_id]),'245',1)
Ind1: Mid(getfieldraw(getbibblob([bib_text].[bib_id]),'245',1),4,1)
Ind2: Mid(getfieldraw(getbibblob([bib_text].[bib_id]),'245',1),5,1)
Use the Mid function to isolate the indicators.
48
Ind1: Mid(getfieldraw(getbibblob([bib_text].[bib_id]),'245',1),4,1)
Ind2: Mid(getfieldraw(getbibblob([bib_text].[bib_id]),'245',1),5,1)
245: getfieldraw(getbibblob([bib_text].[bib_id]),'245',1)
49
GetSubField gives you one occurrence of a MARC subfield.
You need GetFieldRaw and a Blob function with it.
Syntax:
GetSubField(GetFieldRaw(~etc~),
A MARC subfield code
, Which one?
)
50
Example: The second $x from the first 650 in a bib record
GetSubField(GetFieldRaw(GetBibBlob([BIB_TEXT].[BIB_ID]),’650’,1),’x’,2)
Bibliography.
51
The Blob functions can be slow, especially for large databases.
Avoid putting a criterion on a BLOB function.
Try to use the BLOB functions on a subset of your data.
52
To sum up:
GetAuthBlob
GetBibBlob
GetMFHDBlob
GetField GetFieldAll GetFieldRaw
GetSubField
53
Questions about the BLOB?
54
What can you do now that you couldn’t do before you learned the BLOB?
55
Make Table Queries and Subqueries: It’s an Art
56
Make Table Queries and Subqueries fill the same need in different ways.
We’ll focus on Make Table Queries first.
57
If you ever say to yourself...
“I know how to write this query, except that one of the tables I need doesn’t exist,”
...you need a Make Table Query.
58
Example: List all the patron barcodes that appear more than once in my database and show who they’re assigned to.
It’d be pretty easy if you had this table, right?
Patron_Barcode Num_Occurrences
20999000012300
2
20999000076500
3
20999000034500
2
59
So write a query that builds the table:
60
To save the table in your Access database, you need to make it into a Make Table query:
61
Then Access asks what the table should be called.
62
I’ll call it
“Dup Patron Barcode Table”
Tip: You can’t have a table and a query with the same name. If you do, you get an obscure error message. To keep this from happening, I usually include “table” in my table names.
When the query completes, you’ll get this message:
63
If you run the query a second time, Access will delete the results of the previous run, but it will ask you first:
64
Now, when I look at the tables I have available...
65
And when I open it…
66
List all the patron barcodes that appear more than once in my database. That’s easy now!
67
Another example: I want a list of the items that are both charged out and damaged.
That would be easy if I had a table listing the charged items and a table listing the damaged ones.
68
A table of the charged items:
69
A table of the damaged items:
70
And a query to find the items in both:
71
Another use for a Make Table query:
If you have a Blob query that you know will run for a long time, make it a Make Table query.
Start it before you leave work for the day.
I lock my workstation and tape a note to the power button saying that it’s locked.
With luck, in the morning, it will be ready to paste my results into the table.
72
Make Table Query Subquery
Saves the results in your Access database
Doesn’t save the intermediate results
Makes your Access database get bigger
Doesn’t take up room in your Access database
It’s easy to look at the results before you go on to the next step.
You have to make a point of checking your results.
The results can be used by more than one query.
The subquery can be used by more than one query, but it is re-run each time.
Sometimes it’s handy to break up a long-running query into steps.
Sometimes it’s handy to run the whole thing in one step.
73
Subquery example: patron barcodes that appear more than once in my database.
Write the subquery.
Don’t make it a Make Table query.
Don’t run it (except to examine and verify the results).
Save it.
74
75
When I’m about to select the tables for the main query, click the Queries tab and select “Dup patron barcodes subquery”.
76
Then click the Tables tab and select the other tables that you need.
77
Add the links, save the query, and run it.
78
Questions about Make Table queries and subqueries?
79
What can you do now that you know about Subqueries and Make Table Queries?
80
It’s been a whirlwind tour!
Thank you!