Tải bản đầy đủ - 0 (trang)
Hack 52. Get Cleaner And-Based Criteria

Hack 52. Get Cleaner And-Based Criteria

Tải bản đầy đủ - 0trang

TheInoperatormightcometomindasawaytoreducethe

longcriteriastatement.However,thepointistonotincludethe

criteria.ThesolutionistouseboththeInandtheNotoperators.

Notisalogicaloperator:itreversesacondition.Includingitwith

anInoperatorresultsinalistofitemsnottoinclude,which

worksperfectlyforthistypeofquery.

Figure5-49showstheimprovedquery,inwhichthemultipleAnd

statementsareremoved.

Thequeryreturnsthesameresults,withaless-clutteredSQL

statement.



Figure5-49.UsingNotandIntogether



Hack53.CreateanOuterJoin



Accessdoesn'tsupportmakinganouterjoin;here'sa

workaround.

Thestandardjoinbetweentwotablesreturnsrecordsthat

matchbasedonthefieldorfieldsbeingselectedaskeys.Thisis

calledaninnerjoin.Forexample,astatementsuchas"giveme

allcustomersandtheirsalesrecords"usuallyisinterpretedto

meanreturnallthesalesrecordsandthecustomerstowhom

thoserecordsbelong.

Sometimes,though,aleftorrightjoinisrequested.For

example,"givemeallourcustomersandanysalestheymight

havehad"isreallyarequestforaleftjoin.Inotherwords,

returnalltherecordsfromthelefttable(thecustomers)and

anysalesrecordsthatgowiththem.

Figure5-50showshowrecordsreturnedfromaleftjoinquery

look.Inthisexample,therearemorecustomersthanpurchase

daterecords.Someofthecustomershavenopurchasesand

thereforehavenodatainthecolumnontheright.

Arightjoinreturnsallrecordsfromthetableontherightand

onlythoserecordsfromthetableontheleftthatmatchonthe

key.Thethreetypesofjoinsinner,left,andrightareeasytoset

up.Theinneroneisthedefaultwhentwotablesarerelated.

YoucansetthejointypeineithertheRelationshipswindowor

inaquerydesignbydouble-clickingdirectlyonthelinebetween

thetwotables.Figure5-51showstheJoinPropertiesdialogbox

thatappearswhenthelineisdouble-clicked.Thedialog

containsoptionsforthethreejointypes.



Figure5-50.Returnedrecordsfromaleftjoin

query



Figure5-51.Settingjoinproperties



Tài liệu bạn tìm kiếm đã sẵn sàng tải về

Hack 52. Get Cleaner And-Based Criteria

Tải bản đầy đủ ngay(0 tr)

×