📺 Develpreneur YouTube Episode

Video + transcript

SQL Tutorial - Joins and Tuning

2022-06-09 •Youtube

Detailed Notes

1. inner joins vs outer joins

insert into stats(code,value1,value2) values ('TEST',6,12345);

select s.code,l.code from stats s inner join lkp_type l on l.type_id=s.value1;

select s.code,addr.city,addr.state,addr.zip from stats s inner join address addr on addr.t_one_id=s.value1;

select s.code,addr.city,addr.state,addr.zip from stats s left join address addr on addr.t_one_id=s.value1;

select s.code,addr.city,addr.state,addr.zip from stats s left join address addr on addr.t_one_id=s.value1 where addr.city is null;

select s.code,addr.city,addr.state,addr.zip,l.code from stats s left join address addr on addr.t_one_id=s.value1 left join lkp_type l on l.type_id=addr.type_id;

select s.code from stats s where s.value1 not in (select type_id from lkp_type);

select s.code from stats s inner join (select type_id from lkp_type where code='HOME') src on src.type_id=s.value1;

select s.code,addr.city,addr.state,addr.zip from stats s left join address addr on addr.t_one_id=s.value1 where a;

select s.code,l.code from stats s left join lkp_type l on l.type_id=s.value1 where l.code='HOME' or l.code is null;

Transcript Text
[Music]
well hello and welcome back we are
continuing our tutorials of sql focus on
mysql and
mariadb
and uh we're gonna change pace a little
bit uh we've gone through stored
procedures and stored functions and
looked at those
and now we're going to get
a couple of issues or a couple of
sessions tutorials i guess we're going
to talk a little bit about
uh approach and it has to do with
performance tuning and things like that
to some extent
but also just to
talk through some ways to approach
queries
and where clauses and things of that
nature
this is going to be
it's really more like
not really necessarily suggestions as
much as
options because i think you'll find as
you get into these things that
sometimes
there's certain approaches that you're
going to need at certain times
and
it just that's the way it's going to
work but they're also going to be
situations where you have different
approaches and how you do it
will impact
speed things like that because your
your goal is to
leverage as much as possible
the indexes
and other built-in
pieces of the database that allow you to
quickly
query
and indexes are probably the biggest
thing and then we'll we will talk a
little bit as we get further into us
about some different types of indexes
and
a little bit more on those specifically
but today i really just want to talk
about
we're going to look at inner and outer
joins
and so the first thing i want to do is
we're jumping back into
some of the data that we've seen before
and we had this table
uh stats
and it just
has you know some codes some values i'm
gonna do is i'm going to add another
record in there and the key here is
value one
because what i had before is i had value
one
values were from one to three
now i'm going to add one that's got a
value of six and it's particularly
because
this table is not tied to anything else
and we're going to go back and look at
the lookup type
[Music]
and
based on the ids
we only had numbers one through four
so if we wanted to for some reason you
know if if this was just you know we're
just playing around these tables
if
we wanted to do select star
uh let's say
let's do this
let's do select
code
and well we're gonna do this a little
bit so we're gonna like select code from
uh
stats so
that just gives us those but now what we
want to do is we want to do
uh stats so we're going to alias him as
s
so that's just be the stats so we're
going to do
s dot code
comma l dot
code
and let's say we do an inner join
look up type
l
on l dot
type id
equals s dot value 1.
[Music]
so what we want to do now
is we're going to say okay for those
values in value 1
where what would be the
the lookup type for those
now if we do this with an inner join
[Music]
we're going to get
for each of those we're going to match
but notice for our test record that we
created it doesn't exist down here
because
it's an inner join
it says hey if that value doesn't exist
then it's not part of the result set
now if we wanted that to show up anyways
all we have to do
is we do a left join
[Music]
and now we're going to see
that record does show up
but it has a null value
now what we're getting here
the two different result sets is because
of the inner join
it limits
um records that are coming back from
stats
now that's not always what we want to do
in some cases we're going to want
essentially all of the records to come
back but like in this case let us know
if that value doesn't exist
so we could do this
through foreign key relationships and
things like that we can
force
a value to exist but in some cases it
won't and particularly once you get into
uh comparisons and things like that
you're gonna have like uh and even for
example you may have things like
contacts where you may or may not have
an address record
and maybe you want to go through and say
okay
give me a list of all my contacts if i
have an address i want to see it but if
i don't then
that's okay
so you could show me for example a null
and we can do the same thing um we had
for that
show tables
uh what do we call address okay
let's see what our address values are
oh so we can do the same thing so now
let's take
that same one
and now
instead of lookup type let's do address
and we're going to call it a
uh we'll call it adder
and on
adder.something equals that
and here
uh let's do address name well this is
city
state
oh that's a dot
[Music]
and zip
[Music]
and instead of it being value one we're
going to do it on t1id
[Music]
one id
so now
paste that in
so now what we're doing
is we're saying hey if that links up to
an address let's see it i want to see
the city state and zip for that well
again
we're now seeing that we have some
records that don't
uh that don't show up we had here we had
eight rows now we're down to
oh i'm sorry not eight rows nine rows
when we do a select star
but here
we're gonna get eight so we say oh wait
no i do want
ah let me do this
it's gonna be faster to do it this way
plus then you can see it somewhere
if i do that outer join now see that i
get my city state and zip or null and
that may be okay because my result set i
really want to see in this because it's
from stats that
that primary table
typically says i want to get
all the records
the exception would be in a where clause
and so i don't want to
limit based on my joins then i can do
left joins and now what i can do is from
there i can do stuff like
you know i could do stuff that says
um if it's a null
then do something else
and so i could actually say actually
what i want to do with the same thing is
say i only want to do it i want to find
everything where i don't have
a matching address then i could say
where
city is now
uh i'm gonna have to do header.city i'm
sure well actually i won't because it's
in two places but nevertheless so now i
can take that and i can say where city
is null
and that's gonna show me
the cases where i need to get a lookup
value set up properly where i don't have
things properly matched
oh
let's take that let's do that like that
just to make sure we've got that in our
little examples so
what i can do here is i can say you know
here's all the data but i could actually
say hey where is all the situations
where i don't have an address well now i
can pull that
and this would be
in some cases it's going to be
a
a complex type of mapping of data
where i don't want to
i want to do something if the data
exists
but i don't if it's if that mapping is
not there so i could say here
um
so i've got my left join
oops so with my left join i've got tests
but i could say hey for all of these
guys that have one
i want to
get that lookup type
so i could even do there i can say
now if i do interjoin
uh was that lookup type
l on
l dot
what was that l
type id
equals and if i do that in the actual
address
which is going to be adder dot type id i
believe
then
here
um
because i've got an inner join i'm
forcing it and because i don't have the
record from my left join for that test
then
i'm still limiting i'm not going to see
the test record but i could say hey if i
do
if i have an address
[Music]
uh
then
go ahead and give me a oh i'm sorry i'm
not displaying it so let's do
let's do this
uh so let's do lookuptype.name let's
change a little bit
and then
that's gonna be
was it l
dot code
[Music]
oh let's do this and so now i can see
the code if it exists but now i have to
once i do that enter once i do that left
join if i do inner joins then that could
if those are related to what i left
joined to then i can suddenly run into
some issues
now
the difference is that we can
we can do stuff either in inner joins or
through a where clause
so
in order to
um let's go back to this prior run so
here
this one
here we're getting everything back
but then we're getting rid of that we're
saying where inner city is null
or i'm sorry address.city is null so now
we're
you know basically pulling all our
records back and then we're
reducing the result set in the where
clause whereas
we could do it without aware
you know so
because what we really want to do
is we want to find
like for example
we want to flip this
so instead of doing where address city
is null
is
so we've got
here instead of our where
um let's see so this was our left join
so if we look at our left join
what we can do here we could do that
where clause and try to reduce it or
we can try to
pull it separately
so that we're trying to limit the amount
of records that come back which case
we could say here
let's see
then what we'll do instead of pulling
everything
is we go directly to our wear
so it's now not going to pull everything
and actually we can do this
come all the way back here
we're going to instead of even doing the
join and walking through all of this
we want our um
where
what's that going to be s dot value 1.
not in
and we can do select
type id
from look up type
[Music]
so now if we do that
whoop
there we go
so now we're gonna we're getting our
code there and we're saying hey that's
where it doesn't exist now here we're
doing it with an uh where clause
and sometimes that can get pretty
complicated because you're going to end
up having all of these selects
that are out in your where clause
and that can be
in itself a little bit of a problem
because you end up having a whole bunch
of interselects within a select so what
you may want to do
is and so that's uh so you can have that
or
you can have this left join
or
you can try to pull it from
uh let's see what's another one that's i
guess that's really the two ways you
normally are going to do it
you could do it again you can pull it
from a
from a table but if you wherever
possible you want to avoid doing
a full table
so this is something where this is going
to be moderately costly because it's got
this select
now usually what's going to happen is
it's going to because this is in the
where clause
this select is going to occur once
and it's going to it's going to be able
to
tune that in some cases it's not
in particular depending on where you put
your inner selects
particularly if you did it here if you
did it on the select side the left side
of the from instead of the right side of
the wear
then
every
record that it hits it's going to
trigger that select
and then you can have something that
blows up
exponentially basically because now
you've got selects each row each result
set triggers yet another select
and it can get out of hand pretty quick
so typically what you're going to do
there
particularly if you've got like a
compact plex select is instead of doing
an inner select
is that you can actually create a source
so i can do
um
i can do that
and i could do inner join
instead of a table i can actually do
this i'm just going to call him source
and i could say on source
because i can only access what i select
here so on source.type id
equals uh
s dot what was that that was going to be
oh value one
so in this case instead of i can i could
actually limit some of these things out
i can put a where within here so i could
say where uh like type equal where are
my types
uh we're like you know code equals
bus
i guess that's all of them in this case
um
so that's probably not as useful but if
those were different ones
and i can pull that
um then i can actually limit
instead of pulling everything from
lookup type i can do it across only a
couple and do my inner join there
if i do it here what we're going to see
is the same result we saw before yep
except for now i'm just not displaying
all that extra crap
because here instead of
an inner join of lookup type
i'm just doing the type id so it returns
a little bit less but it doesn't really
matter what i would really want to do
it'd say like where
uh
what was that
let's say
look uh well i can just do it with here
so look up type
let's go look at those values real quick
somewhere in here
uh
let's just do this
look up type
uh so let's say where code equals home
let's say
so now what i'm doing
is instead of doing an inner join that's
going to do a table scan across that i'm
just going to say
let's do it where all the home addresses
are and we're going to find that you
know there's only a couple there oh and
i so there were so now we're getting
this lowered result set
and instead of
where i could instead
move this out
so
uh
let's see where did i have that before
here we go
so i could even do here where address
that was where i drew a city
i can just change it so i can say even
with this left join
i could say where
address
[Applause]
oh that's not on the lookup
uh
here we go
so i can actually play around with these
quite a bit
so here
uh enter join on that
and then i can say
where l.code
equals home
okay so i get those but now also i could
enter join i could do a left join on
that and i could say hey go ahead and
show me all of them
[Music]
but
only
if it's home do i want to see something
stats left join that on that
oh and in this case
i'm still going to change this up a
little bit because
l code is going to be null so i could
say or
well that code is null
and now what i'm going to do is i'm
going to find
the non-maps
or the homes
so we can move our wares around quite a
bit
and that will make
a bit of a difference in the performance
tuning now we're only dealing with you
know a half dozen records or something
like that at most so you're not gonna
see it but if you have a database even
with hundreds of records uh definitely
if you get into thousands or tens of
thousands or millions then you can see
some dramatic changes depending on where
you put your where clause
and
how you do
indexes which is something we will refer
to we'll get into that a little bit
later about how to do some indexing
and uh where to make sure that we have
indexes or
where it may be beneficial to do so
i think i'll do it for now i just wanted
to play around with those a little bit i
don't have complex examples yet
in our test data
and i will probably
find a nice little you know demo
database that we can use i may even
provide you one
so we can get a little deeper in some of
our
more complex types of queries that being
said we'll wrap this one up so go out
there have yourself a great day a great
week and we will talk to you
next time
you
Transcript Segments
0.43

[Music]

27.039

well hello and welcome back we are

29.039

continuing our tutorials of sql focus on

32.399

mysql and

34.719

mariadb

36.079

and uh we're gonna change pace a little

38.32

bit uh we've gone through stored

40

procedures and stored functions and

41.76

looked at those

43.12

and now we're going to get

44.48

a couple of issues or a couple of

46.719

sessions tutorials i guess we're going

48.32

to talk a little bit about

50.719

uh approach and it has to do with

52.8

performance tuning and things like that

54.48

to some extent

56.079

but also just to

58.559

talk through some ways to approach

61.039

queries

62.96

and where clauses and things of that

65.199

nature

69.84

this is going to be

73.28

it's really more like

75.04

not really necessarily suggestions as

77.52

much as

79.04

options because i think you'll find as

81.439

you get into these things that

83.84

sometimes

85.2

there's certain approaches that you're

86.4

going to need at certain times

88.64

and

89.68

it just that's the way it's going to

91.28

work but they're also going to be

92.479

situations where you have different

94.079

approaches and how you do it

97.36

will impact

99.04

speed things like that because your

101.52

your goal is to

104.64

leverage as much as possible

107.36

the indexes

109.119

and other built-in

111.439

pieces of the database that allow you to

115.04

quickly

116.079

query

117.28

and indexes are probably the biggest

118.719

thing and then we'll we will talk a

120.88

little bit as we get further into us

122.32

about some different types of indexes

125.04

and

125.759

a little bit more on those specifically

128.08

but today i really just want to talk

129.92

about

130.959

we're going to look at inner and outer

132.879

joins

134.56

and so the first thing i want to do is

136

we're jumping back into

137.92

some of the data that we've seen before

140.08

and we had this table

142.72

uh stats

144.879

and it just

146.319

has you know some codes some values i'm

149.2

gonna do is i'm going to add another

151.84

record in there and the key here is

154.319

value one

156.319

because what i had before is i had value

158.319

one

159.68

values were from one to three

162.64

now i'm going to add one that's got a

163.92

value of six and it's particularly

165.92

because

167.12

this table is not tied to anything else

169.92

and we're going to go back and look at

172.16

the lookup type

173.92

[Music]

176.56

and

177.68

based on the ids

180

we only had numbers one through four

182.8

so if we wanted to for some reason you

185.44

know if if this was just you know we're

187.599

just playing around these tables

189.84

if

191.599

we wanted to do select star

194.319

uh let's say

196.72

let's do this

199.2

let's do select

201.28

code

203.84

and well we're gonna do this a little

205.599

bit so we're gonna like select code from

209.04

uh

210.84

stats so

212.799

that just gives us those but now what we

214.64

want to do is we want to do

216.72

uh stats so we're going to alias him as

218.959

s

220.08

so that's just be the stats so we're

221.44

going to do

222.72

s dot code

224.84

comma l dot

227.84

code

232.56

and let's say we do an inner join

235.599

look up type

238

l

238.959

on l dot

242

type id

244

equals s dot value 1.

247.45

[Music]

249.28

so what we want to do now

251.2

is we're going to say okay for those

252.48

values in value 1

255.68

where what would be the

258.16

the lookup type for those

260.239

now if we do this with an inner join

262.12

[Music]

264

we're going to get

265.84

for each of those we're going to match

267.28

but notice for our test record that we

269.36

created it doesn't exist down here

271.84

because

273.04

it's an inner join

275.04

it says hey if that value doesn't exist

277.04

then it's not part of the result set

279.759

now if we wanted that to show up anyways

282.88

all we have to do

284.639

is we do a left join

285.99

[Music]

287.28

and now we're going to see

289.44

that record does show up

291.44

but it has a null value

294

now what we're getting here

296.72

the two different result sets is because

299.759

of the inner join

302.639

it limits

304.72

um records that are coming back from

306.72

stats

308.24

now that's not always what we want to do

311.44

in some cases we're going to want

313.6

essentially all of the records to come

315.199

back but like in this case let us know

318.16

if that value doesn't exist

320.8

so we could do this

323.12

through foreign key relationships and

324.56

things like that we can

326.24

force

327.28

a value to exist but in some cases it

330.08

won't and particularly once you get into

333.6

uh comparisons and things like that

335.6

you're gonna have like uh and even for

337.52

example you may have things like

339.44

contacts where you may or may not have

342

an address record

344.08

and maybe you want to go through and say

345.6

okay

346.8

give me a list of all my contacts if i

349.84

have an address i want to see it but if

352.479

i don't then

353.84

that's okay

355.039

so you could show me for example a null

357.919

and we can do the same thing um we had

360.96

for that

362.4

show tables

364.24

uh what do we call address okay

366.639

let's see what our address values are

370.24

oh so we can do the same thing so now

372.08

let's take

374

that same one

376.24

and now

382.08

instead of lookup type let's do address

385.28

and we're going to call it a

386.88

uh we'll call it adder

389.28

and on

390.52

adder.something equals that

393.199

and here

396.319

uh let's do address name well this is

398.56

city

403.6

state

408.88

oh that's a dot

410.04

[Music]

411.52

and zip

413.77

[Music]

417.44

and instead of it being value one we're

419.599

going to do it on t1id

422

[Music]

426

one id

428.16

so now

432.88

paste that in

435.12

so now what we're doing

437.599

is we're saying hey if that links up to

438.96

an address let's see it i want to see

440.4

the city state and zip for that well

442.4

again

443.44

we're now seeing that we have some

445.68

records that don't

448.08

uh that don't show up we had here we had

451.68

eight rows now we're down to

455.52

oh i'm sorry not eight rows nine rows

457.919

when we do a select star

460.56

but here

461.599

we're gonna get eight so we say oh wait

462.96

no i do want

464.56

ah let me do this

466.639

it's gonna be faster to do it this way

472

plus then you can see it somewhere

478.16

if i do that outer join now see that i

480.08

get my city state and zip or null and

481.919

that may be okay because my result set i

484.16

really want to see in this because it's

486.4

from stats that

488.08

that primary table

489.84

typically says i want to get

492.4

all the records

494.24

the exception would be in a where clause

498

and so i don't want to

500.72

limit based on my joins then i can do

502.96

left joins and now what i can do is from

506.08

there i can do stuff like

508.16

you know i could do stuff that says

510.8

um if it's a null

512.8

then do something else

515.2

and so i could actually say actually

517.599

what i want to do with the same thing is

519.44

say i only want to do it i want to find

521.919

everything where i don't have

524.24

a matching address then i could say

526.8

where

528

city is now

533.12

uh i'm gonna have to do header.city i'm

535.04

sure well actually i won't because it's

536.8

in two places but nevertheless so now i

538.8

can take that and i can say where city

541.2

is null

543.36

and that's gonna show me

545.44

the cases where i need to get a lookup

547.68

value set up properly where i don't have

549.519

things properly matched

554.399

oh

556.72

let's take that let's do that like that

559.519

just to make sure we've got that in our

560.959

little examples so

563.92

what i can do here is i can say you know

567.12

here's all the data but i could actually

568.56

say hey where is all the situations

570.08

where i don't have an address well now i

572

can pull that

573.76

and this would be

577.04

in some cases it's going to be

580.399

a

583.36

a complex type of mapping of data

587.12

where i don't want to

588.959

i want to do something if the data

591.04

exists

592.32

but i don't if it's if that mapping is

594.64

not there so i could say here

599.519

um

600.48

so i've got my left join

602.32

oops so with my left join i've got tests

604.72

but i could say hey for all of these

606.24

guys that have one

608.399

i want to

610.16

get that lookup type

613.12

so i could even do there i can say

619.2

now if i do interjoin

621.92

uh was that lookup type

624.88

l on

626.64

l dot

629.12

what was that l

630.8

type id

634.88

equals and if i do that in the actual

636.959

address

638.399

which is going to be adder dot type id i

641.2

believe

645.519

then

647.92

here

649.36

um

650.959

because i've got an inner join i'm

652.72

forcing it and because i don't have the

654.88

record from my left join for that test

658.079

then

659.12

i'm still limiting i'm not going to see

660.72

the test record but i could say hey if i

662.8

do

663.68

if i have an address

666.37

[Music]

667.839

uh

669.36

then

670.399

go ahead and give me a oh i'm sorry i'm

672.959

not displaying it so let's do

675.76

let's do this

679.12

uh so let's do lookuptype.name let's

681.6

change a little bit

683.36

and then

685.839

that's gonna be

687.2

was it l

688.64

dot code

691.55

[Music]

694.399

oh let's do this and so now i can see

697.04

the code if it exists but now i have to

699.36

once i do that enter once i do that left

701.6

join if i do inner joins then that could

704.48

if those are related to what i left

706.399

joined to then i can suddenly run into

709.12

some issues

711.2

now

712.56

the difference is that we can

716.48

we can do stuff either in inner joins or

719.68

through a where clause

721.36

so

722.56

in order to

726.399

um let's go back to this prior run so

730.639

here

732

this one

734.24

here we're getting everything back

737.36

but then we're getting rid of that we're

739.76

saying where inner city is null

743.12

or i'm sorry address.city is null so now

745.36

we're

746.24

you know basically pulling all our

747.6

records back and then we're

749.839

reducing the result set in the where

751.76

clause whereas

755.12

we could do it without aware

758.079

you know so

760.56

because what we really want to do

762.639

is we want to find

764.399

like for example

766.399

we want to flip this

767.92

so instead of doing where address city

769.68

is null

773.76

is

776.16

so we've got

777.92

here instead of our where

781.12

um let's see so this was our left join

783.2

so if we look at our left join

786.48

what we can do here we could do that

788.16

where clause and try to reduce it or

792.16

we can try to

795.12

pull it separately

796.959

so that we're trying to limit the amount

798.56

of records that come back which case

801.839

we could say here

806.639

let's see

808.24

then what we'll do instead of pulling

810.72

everything

811.839

is we go directly to our wear

815.279

so it's now not going to pull everything

817.44

and actually we can do this

822.56

come all the way back here

828.079

we're going to instead of even doing the

829.92

join and walking through all of this

833.44

we want our um

836

where

836.959

what's that going to be s dot value 1.

843.92

not in

846.48

and we can do select

853.04

type id

857.04

from look up type

860.59

[Music]

865.68

so now if we do that

868.839

whoop

870.56

there we go

871.76

so now we're gonna we're getting our

872.959

code there and we're saying hey that's

874.32

where it doesn't exist now here we're

876.32

doing it with an uh where clause

880

and sometimes that can get pretty

881.76

complicated because you're going to end

883.68

up having all of these selects

886.639

that are out in your where clause

890.32

and that can be

891.92

in itself a little bit of a problem

893.44

because you end up having a whole bunch

894.8

of interselects within a select so what

898.56

you may want to do

904.88

is and so that's uh so you can have that

908.639

or

909.68

you can have this left join

912.48

or

914.399

you can try to pull it from

917.199

uh let's see what's another one that's i

919.76

guess that's really the two ways you

921.199

normally are going to do it

923.68

you could do it again you can pull it

925.6

from a

927.76

from a table but if you wherever

929.839

possible you want to avoid doing

933.04

a full table

935.36

so this is something where this is going

936.72

to be moderately costly because it's got

939.44

this select

941.12

now usually what's going to happen is

942.399

it's going to because this is in the

944

where clause

945.44

this select is going to occur once

948.48

and it's going to it's going to be able

950.24

to

951.04

tune that in some cases it's not

953.68

in particular depending on where you put

955.279

your inner selects

957.12

particularly if you did it here if you

959.12

did it on the select side the left side

961.12

of the from instead of the right side of

963.759

the wear

965.44

then

966.399

every

967.519

record that it hits it's going to

970.079

trigger that select

971.68

and then you can have something that

973.199

blows up

975.04

exponentially basically because now

977.36

you've got selects each row each result

980.079

set triggers yet another select

982.959

and it can get out of hand pretty quick

985.68

so typically what you're going to do

986.959

there

988.88

particularly if you've got like a

989.839

compact plex select is instead of doing

992.8

an inner select

994.32

is that you can actually create a source

996.48

so i can do

1000.48

um

1001.519

i can do that

1004.72

and i could do inner join

1007.759

instead of a table i can actually do

1009.6

this i'm just going to call him source

1013.839

and i could say on source

1016.56

because i can only access what i select

1018.88

here so on source.type id

1022.839

equals uh

1024.799

s dot what was that that was going to be

1027.919

oh value one

1030.72

so in this case instead of i can i could

1032.72

actually limit some of these things out

1036

i can put a where within here so i could

1038.16

say where uh like type equal where are

1040.4

my types

1042.48

uh we're like you know code equals

1044.88

bus

1046.64

i guess that's all of them in this case

1048.48

um

1052

so that's probably not as useful but if

1053.76

those were different ones

1055.919

and i can pull that

1057.36

um then i can actually limit

1059.76

instead of pulling everything from

1060.96

lookup type i can do it across only a

1062.64

couple and do my inner join there

1065.28

if i do it here what we're going to see

1066.64

is the same result we saw before yep

1069.28

except for now i'm just not displaying

1070.64

all that extra crap

1074

because here instead of

1076.24

an inner join of lookup type

1079.52

i'm just doing the type id so it returns

1081.919

a little bit less but it doesn't really

1083.6

matter what i would really want to do

1084.88

it'd say like where

1086.88

uh

1087.84

what was that

1090.48

let's say

1093.36

look uh well i can just do it with here

1095.039

so look up type

1097.2

let's go look at those values real quick

1100.64

somewhere in here

1105.28

uh

1106.4

let's just do this

1111.6

look up type

1114.08

uh so let's say where code equals home

1116.08

let's say

1118.48

so now what i'm doing

1120.84

is instead of doing an inner join that's

1123.28

going to do a table scan across that i'm

1125.36

just going to say

1127.52

let's do it where all the home addresses

1130.08

are and we're going to find that you

1131.52

know there's only a couple there oh and

1133.36

i so there were so now we're getting

1135.28

this lowered result set

1137.6

and instead of

1140

where i could instead

1142.48

move this out

1144.72

so

1145.44

uh

1146.24

let's see where did i have that before

1149.679

here we go

1153.84

so i could even do here where address

1155.44

that was where i drew a city

1159.039

i can just change it so i can say even

1160.72

with this left join

1163.6

i could say where

1166.88

address

1167.6

[Applause]

1170.96

oh that's not on the lookup

1172.96

uh

1173.919

here we go

1176.72

so i can actually play around with these

1178.24

quite a bit

1179.6

so here

1182.32

uh enter join on that

1185.039

and then i can say

1190.96

where l.code

1193.2

equals home

1197.039

okay so i get those but now also i could

1199.12

enter join i could do a left join on

1200.96

that and i could say hey go ahead and

1202.64

show me all of them

1203.93

[Music]

1205.36

but

1206.48

only

1207.52

if it's home do i want to see something

1215.28

stats left join that on that

1219.679

oh and in this case

1221.679

i'm still going to change this up a

1223.12

little bit because

1224.88

l code is going to be null so i could

1226.72

say or

1228.96

well that code is null

1231.919

and now what i'm going to do is i'm

1233.28

going to find

1235.6

the non-maps

1237.28

or the homes

1239.6

so we can move our wares around quite a

1242.159

bit

1245.2

and that will make

1246.72

a bit of a difference in the performance

1248.72

tuning now we're only dealing with you

1250.799

know a half dozen records or something

1252.559

like that at most so you're not gonna

1254.64

see it but if you have a database even

1256.799

with hundreds of records uh definitely

1258.72

if you get into thousands or tens of

1260.24

thousands or millions then you can see

1262.559

some dramatic changes depending on where

1266

you put your where clause

1268.559

and

1269.76

how you do

1271.2

indexes which is something we will refer

1273.52

to we'll get into that a little bit

1275.28

later about how to do some indexing

1278.08

and uh where to make sure that we have

1280.24

indexes or

1281.76

where it may be beneficial to do so

1285.28

i think i'll do it for now i just wanted

1287.2

to play around with those a little bit i

1288.559

don't have complex examples yet

1292.159

in our test data

1293.679

and i will probably

1295.36

find a nice little you know demo

1296.88

database that we can use i may even

1298.88

provide you one

1300.64

so we can get a little deeper in some of

1302.32

our

1303.28

more complex types of queries that being

1305.44

said we'll wrap this one up so go out

1307.76

there have yourself a great day a great

1309.919

week and we will talk to you

1312.559

next time

1329.76

you