📺 Develpreneur YouTube Episode

Video + transcript

SQL tutorial - Day 5

2022-04-19 •Youtube

Detailed Notes

Notes from the tutorial:

1. More data insert into tutorial_parent(username,email,userLogin,pwd) values ('user 3','[email protected]','user3','testuser3'); insert into tutorial_parent(t_one_id,username,email,userLogin,pwd) values (1,'user 4','[email protected]','user4','testuser4'); 2. select tp.username,tp.email,tp.userLogin,t1.address_name,t1.city, t1.state,t1.zip from tutorial_parent as tp inner join tutorial_one t1 on tp.t_one_id=t1.t_one_id;

select tp.username,tp.email,tp.userLogin,t1.address_name,t1.city, t1.state,t1.zip from tutorial_parent as tp,tutorial_one t1 where tp.t_one_id=t1.t_one_id;

select tp.username,tp.email,tp.userLogin,t1.address_name,t1.city, t1.state,t1.zip from tutorial_parent as tp left join tutorial_one t1 on tp.t_one_id=t1.t_one_id;

3. insert types insert into lkp_type(code,name) values ('HOME','Home Address'); insert into lkp_type(code,name) values ('MAIL','Mailing Address'); insert into lkp_type(code,name) values ('BUS','Business Address'); 4. alter table ALTER TABLE tutorial_one ADD type_id int null AFTER zip; ater table tutorial_one add constraint type_fk FOREIGN KEY (type_id) REFERENCES lkp_type(type_id)

5. select tp.username,tp.email,tp.userLogin,t1.address_name,t1.city, t1.state,t1.zip,lt.name from tutorial_parent as tp left join tutorial_one t1 on tp.t_one_id=t1.t_one_id inner join lkp_type lt on lt.type_id=t1.type_id

select tp.username,tp.email,tp.userLogin,t1.address_name,t1.city, t1.state,t1.zip from tutorial_parent as tp,tutorial_one t1, lkp_type lt where tp.t_one_id=t1.t_one_id and lt.type_id = t1.type_id;

Transcript Text
[Music]
three
two
one
well hello and welcome back
we are continuing our mysql sql database
uh sorry my sequel miss mariadb sql
tutorial stuff
and we're going to continue talking
about tables today
so if we go ahead and jump into
whoops
i should probably get out to my machine
and then
uh let's see let's do
what are we going to talk about today
okay so first thing we're going to do is
we're going to jump into our
[Music]
uh
jump into our database
tutor dash p
and we are going to use our tutorial
database yep
if you remember last time we had
two tables
we had a table one
and parent table one is sort of like an
address
and um
the parent is
like a user and so
what i want to do this time
is i'm going to take a couple records
and insert them
into the parent table
because what we do here is we're going
to play around a little bit with the
inner and outer joins
now what we have here
is uh some data let's do this
from
tutorial parent
i want to show you the data real quick
that we have first so that's what we
have in parent and in one we've got so
what we have for we'll call them users
we've got four users and we've got three
addresses
and if you remember
from foreign key relationships
we have in the parent table we have this
t1 id which ties it back to a record in
the tutorial 1 table
and so we have two of the records here
are tied to record three
one isn't tied to anything and one of
them is tied to record one
now if we go back to
i'm gonna steal my
query here that we used from last time
and this query we're selecting from the
parent the username email login and then
from the address or the tutorial1 table
address name citystate zip
and as we can see here although we have
and we did a select
you know we didn't have anything else
anywhere clause or anything so
theoretically it should take
because it did from uh tutorial parent
it should give us all the records back
in tutorial parent however it doesn't
because we have this inner join that
says i'm only going to take back rows
where
my t1 id exists somewhere in the other
t1 id
and so that's where we get the results
here
where we don't see
user name three
because they're not tied to anybody
but we also do see here where username
one and two
have the same address we can see here
they're both tied to address two and
then the other guy is tied to address
four
now that
is
an inner join but if we just do an outer
join or more specifically a left join
and change that keyword inner
to left that's the only thing i'm going
to change
now we're going to see all of them
because what this says
is it says
go ahead and give me
the data from
where does the left join
give me the data from tutorial one let
me see if i expand that out it'll be a
little bit yeah
so give me the data from tutorial one
but only if i can connect to it what it
does otherwise is it sends us nulls so
we can see here
for user three
where what we have is a user that's tied
to no address is guess what it doesn't
show us an address it just shows us
nulls from this address name city state
and zip and all of those fields came out
of the tutorial one
now i do want to
before we move on i want to do a it's
it's an old-school way to do joins
and
i'm going to show you just because you
may run into it
but this
approach of using of specifically doing
like inners or
inner or left joins is a much better way
to do it
and the way that looks
i can't blow that up enough probably
so what i'm going to do instead i'm
going to take the inner join and then
we'll show it i'll show it to you in a
second here
is instead i'm going to take the same
selects
but i can say
here
where i said from tutorial parent as tp
then i can do a comma and give it the
second table which is going to be
tutorial one or as many tables as i want
and then instead of this whole inner
join
then i'm going to say
where
tp1 equal or tp
one id equals t1 one id and i'll do this
here so it's a little bigger to see
and
so here we go is so we have the same
fields
what we do is instead of seeing multiple
basically you think of as like a line
per table that we're joining
we see all of these
um here we go from our two here's our
two tables
and then we just have a where clause so
it's just select stuff from a list of
tables and then a where clause the
problem is
is that if we do the same thing
and we don't include a where clause
we get
every possible combination you get a
cross join
where it basically says for every row
in the first table which is tutorial
parent
pair it with a as in p not parrot is in
the bird but p a i r the record with a
record in tutorial one so you can see
here
user one exists three times
one for
each record
that's in tutorial one
and so you can see here where he has
name two three and four
for user one and then here you see the
same thing repeated for two
and so you end up with these things that
are
really not what you wanted and as you
can see here can be huge i mean this was
just three records by four records let's
say you do that with uh
two tables that have 10 000 records each
you have just suddenly created a huge
query huge result set
none of which is useful
now there are some things you can do to
try to
uh simplify that out a little bit
but that would be after the fact and i
think that's part of why
we've moved to this
uh this use of inner joins and left and
inner left outer joins using those
is that
now it's much easier to see what the
you give it like a primary table and it
starts there
and then it's going to start whittling
away before it even leaves
before that data even leaves the server
which makes it
easier to tune
and you're going to find that your
queries are dramatically different
in speed if i were to take this same
query
and i could
if i did this query with the where
that one that did work
you know that one only gave me the three
but if i used that along with the one
that was the inner join where was the
inner join
um
that's left joint here if i do that same
one so you can see here
these are the identical result sets
and for all these are identical
queries
i guess as far as like this is what i'm
asking but how i ask it is different
and in a lot of cases a lot of modern
databases you will find
that using the inner join approach like
this is going to be substantially faster
i have seen
a pretty nice percentage uh as
as far as like set up to like 70 and 80
percent
better running
queries and maybe even more than that
doing it with
this inner join this inner join as
opposed to doing like the multiple table
listing
and it also it helps with
it we'll get into in
the idea of indexes and stuff like that
but
this is going to be just showing you
this so that you can see it but you want
to use this this inner join approach
so now
let's go back over here now let's go
ahead
and i'm going to create a new table this
third table i'm going to create
i'm going to call it lookup type or lkp
type
and what you can see here
is all it is is it's a type id
it's a 100 up to 100 character name i'm
going to default it to undefined i'm
going to have a code that's a varchar4
and then its primary key is type id
and so now i'm going to because i
cheated a little bit earlier i have
somewhere in here
some sql to create a few rows
so i'm going to create those rows
and whatever i did i didn't do right so
let's go back to this
it's called lookup type
oh that's not insert into table
that's what happens when you don't
pre-run your stuff but that's okay at
least i'm saving us a little bit of time
and okay and then if i do select star
from lookup type
then i'm going to see the three records
i created with their id so now i've got
this idea of a home address a mailing
address and a business address and what
i'm going to do is i'm going to go into
tutorial 1 table where we see our
addresses and i'm going to add a type
a type field
because we're going to get a little more
complicated here so first thing i'm
going to do is i'm going to add a column
so i'm adding a column called type id
to tutorial 1 and it's going to show up
after zip so now if i do describe
tutorial 1. i'm going to see that i have
now this type id
and by default it's null and if i do
this
select star from tutorial 1
then i'm going to see that i have the
type id of null everywhere
now let's just make it simple
and
i'm going to update
well let's do it this way first now what
i'm going to do is if you can remember
we used a reference in the past we used
a foreign key reference uh
we use this constraint in order to tie
a address essentially what an address is
back to a person
and so we're going to do the same thing
but we're going to use an alter
so what we can do
is we can alter the table
and i'll show you here
is oops
i have a typo in there anyways so i'm
going to come in like we saw before i'm
going to alter table i'm going to give
it a table name so this is going to be
that tutorial 1 table
and now i'm going to add a constraint
before we added a column
i'm going to give it the constraint name
what type is it
and then basically you know what key or
what com what column which would be type
id am i using
in tutorial one and then what am i tying
it off to i'm going to tie it to lookup
type type id
i get it
there we go
and so now
going back to my type ids if i wanted to
update
tutorial 1.
and i want to set the type id
equal to 4 let's do that because look
there is we'll note that there is no 4
so it should complain as you remember
because that foreign key is going to
kick off here in a second and sure
enough
foreign key constraint fails
uh
the type fk and that's the name of the
that's my foreign key and it does
because i can't find number four in
there but if i change it over to three
then boom
i've got it and if i go select star from
tutorial one now everybody's type is
going to be type three
which is a business address
so now if we had now we've got three
tables and so that's where i want to go
next is i'm going to take
our earlier one
let's do this
get my notes changed a little bit
and i will show you this
a little better in a bigger
font
so now what i'm going to do is i'm going
to actually do two inner joins
it's i'm going to interjoin
the table lookup type
and i'll call him
and i'm going to join that on lt dot
type id equals
he is in tutorial 1
which is t1 type id
and so now all i'm going to do is i'm
just going to take
after all of this
i'm going to come in here i'm going to
do an lt dot
uh we'll do that code for now
and so if we take that and we jump over
in our database
so no this is i haven't changed too much
is i'm saying i'm going to add another
table that i'm going to link data to
and i'm only going to show just one
additional
field
and so doing that
now i see
that i have my
where is it i have my
tutorial parent data
now i can see my tutorial child data
and now i can see
my lookup type
and i could change that so i could call
it instead of
uh oh wow let's do it this one that's
it'll be easier to edit it here so let's
say instead of code i say name
and i can make either of these a left
join so i come in here and do a left
join
and i can do this and make this a left
join
we'll make both of them and then you're
going to see
that it'll be able to flow through
and
i see nulls across the board
here
now
if i were to do an inner join on this
first one the inner join back to the
address
then this row would disappear because it
would say i have to have
an address but now
if i do an inner join
here
but leave a left join for the type
i'm sorry leave a left join
and then do an inner join on the type
then i'm also going to lose it
we'll see here
because
even though i did a left join for the
address i said were said hey give me
nulls if you know if you find nulls
that's fine
but
i came back with the inner join and said
i have to have a matching name
and so now
i'm stuck because it says hey i'm
looking up the code
you gave me a null i can't find the null
code anywhere so that's not going to
work
and so you can you know mix and match
your inner joins and left joins but
realize that once you do one that's
entered you're going to restrict some of
your some of the data that comes back
so it can be a little bit
complicated
and that's why i wanted to get us to at
least three tables now if we want to
take our earlier example
[Music]
i'll show you how it gets really
complicated quick if we do our
one with the commas
uh
that's the inner join
where did i put that
nope not that one
let's create table
it's another
here we
go so let's take our earlier one
where we did the comma version so we did
so we do a select from table 1 comma
table 2
comma
table three lookup type
lt
now
if we want to do the inner join we're
going to say where
the t1 ids match and
lt dot
code id or type id
equals was that t1
dot type id
and so you end up having these really
huge
where clauses yep there we go and so i
just pasted that in
and you have these really huge where
clauses but i do get the right data it's
just now
which is basically a processing thing
it's now it's
basically pulling everything and then
it's going to start pulling it out as
opposed to
while it's pulling data limiting what
it's pulling even in the first
essentially like the first pass
now
i think that's a good spot for us to
stop on this one we've added a third
table we've got some additional data
and we're cruising along learning a
little bit more about our you know our
selects
we've touched on some updates and things
like that
and so now we're going to get we'll
continue moving on the next episode that
being said we'll wrap this one up so go
out there and have yourself a great day
a great week and we will talk to you
next time
you
Transcript Segments
0.48

[Music]

26.16

three

27.119

two

28.08

one

28.88

well hello and welcome back

31.679

we are continuing our mysql sql database

35.36

uh sorry my sequel miss mariadb sql

39.2

tutorial stuff

41.28

and we're going to continue talking

42.8

about tables today

45.2

so if we go ahead and jump into

48.239

whoops

50.719

i should probably get out to my machine

56.719

and then

58.399

uh let's see let's do

60.399

what are we going to talk about today

62.399

okay so first thing we're going to do is

63.6

we're going to jump into our

65.28

[Music]

68.159

uh

69.439

jump into our database

72.56

tutor dash p

77.84

and we are going to use our tutorial

80.64

database yep

84.24

if you remember last time we had

86.88

two tables

90.159

we had a table one

91.84

and parent table one is sort of like an

93.92

address

95.2

and um

97.119

the parent is

98.96

like a user and so

102.159

what i want to do this time

104.159

is i'm going to take a couple records

106.56

and insert them

108.96

into the parent table

112.24

because what we do here is we're going

113.439

to play around a little bit with the

115.84

inner and outer joins

118.24

now what we have here

120.159

is uh some data let's do this

124

from

126.56

tutorial parent

130.319

i want to show you the data real quick

131.76

that we have first so that's what we

133.84

have in parent and in one we've got so

136.8

what we have for we'll call them users

139.28

we've got four users and we've got three

141.599

addresses

143.04

and if you remember

144.879

from foreign key relationships

147.28

we have in the parent table we have this

150.4

t1 id which ties it back to a record in

153.28

the tutorial 1 table

155.44

and so we have two of the records here

157.599

are tied to record three

160.319

one isn't tied to anything and one of

162.16

them is tied to record one

165.44

now if we go back to

167.92

i'm gonna steal my

169.68

query here that we used from last time

174.56

and this query we're selecting from the

177.599

parent the username email login and then

180.48

from the address or the tutorial1 table

183.36

address name citystate zip

185.68

and as we can see here although we have

188.56

and we did a select

190.239

you know we didn't have anything else

192.56

anywhere clause or anything so

194

theoretically it should take

196

because it did from uh tutorial parent

199.2

it should give us all the records back

200.72

in tutorial parent however it doesn't

204

because we have this inner join that

206.4

says i'm only going to take back rows

209.519

where

210.72

my t1 id exists somewhere in the other

213.76

t1 id

215.2

and so that's where we get the results

216.64

here

217.519

where we don't see

219.84

user name three

222.239

because they're not tied to anybody

224.4

but we also do see here where username

226.64

one and two

228.56

have the same address we can see here

230.4

they're both tied to address two and

232

then the other guy is tied to address

233.84

four

235.2

now that

236.4

is

237.519

an inner join but if we just do an outer

240.799

join or more specifically a left join

242.72

and change that keyword inner

245.28

to left that's the only thing i'm going

246.799

to change

247.84

now we're going to see all of them

249.68

because what this says

251.76

is it says

252.959

go ahead and give me

255.04

the data from

256.56

where does the left join

258.239

give me the data from tutorial one let

260.959

me see if i expand that out it'll be a

262.479

little bit yeah

263.68

so give me the data from tutorial one

266.32

but only if i can connect to it what it

269.44

does otherwise is it sends us nulls so

272.639

we can see here

274.639

for user three

277.12

where what we have is a user that's tied

279.759

to no address is guess what it doesn't

282.4

show us an address it just shows us

283.919

nulls from this address name city state

286.4

and zip and all of those fields came out

289.04

of the tutorial one

292

now i do want to

294.32

before we move on i want to do a it's

297.919

it's an old-school way to do joins

300.96

and

302.4

i'm going to show you just because you

304.56

may run into it

306.24

but this

307.68

approach of using of specifically doing

310.32

like inners or

312

inner or left joins is a much better way

315.44

to do it

316.88

and the way that looks

320.32

i can't blow that up enough probably

323.28

so what i'm going to do instead i'm

324.72

going to take the inner join and then

325.919

we'll show it i'll show it to you in a

327.12

second here

328.639

is instead i'm going to take the same

330.4

selects

332.72

but i can say

334.16

here

335.28

where i said from tutorial parent as tp

338.72

then i can do a comma and give it the

340.479

second table which is going to be

342

tutorial one or as many tables as i want

346.4

and then instead of this whole inner

347.84

join

351.12

then i'm going to say

352.72

where

354.56

tp1 equal or tp

356.96

one id equals t1 one id and i'll do this

359.44

here so it's a little bigger to see

364.84

and

366.4

so here we go is so we have the same

368

fields

370.4

what we do is instead of seeing multiple

374.08

basically you think of as like a line

376

per table that we're joining

378

we see all of these

381.12

um here we go from our two here's our

383.12

two tables

384.479

and then we just have a where clause so

386.4

it's just select stuff from a list of

388.88

tables and then a where clause the

390.72

problem is

392.24

is that if we do the same thing

395.759

and we don't include a where clause

398.639

we get

399.759

every possible combination you get a

401.919

cross join

403.28

where it basically says for every row

406.479

in the first table which is tutorial

408.56

parent

409.919

pair it with a as in p not parrot is in

412.8

the bird but p a i r the record with a

416.639

record in tutorial one so you can see

419.12

here

420.56

user one exists three times

422.96

one for

424.639

each record

426.24

that's in tutorial one

428.8

and so you can see here where he has

430.72

name two three and four

432.72

for user one and then here you see the

435.52

same thing repeated for two

437.28

and so you end up with these things that

438.72

are

439.68

really not what you wanted and as you

442

can see here can be huge i mean this was

444.319

just three records by four records let's

446.479

say you do that with uh

448.319

two tables that have 10 000 records each

450.96

you have just suddenly created a huge

453.759

query huge result set

456.24

none of which is useful

458

now there are some things you can do to

460.16

try to

461.919

uh simplify that out a little bit

465.28

but that would be after the fact and i

467.44

think that's part of why

469.12

we've moved to this

471.44

uh this use of inner joins and left and

474.639

inner left outer joins using those

477.52

is that

478.8

now it's much easier to see what the

481.28

you give it like a primary table and it

483.36

starts there

484.8

and then it's going to start whittling

487.12

away before it even leaves

489.36

before that data even leaves the server

491.12

which makes it

492.639

easier to tune

494.08

and you're going to find that your

495.36

queries are dramatically different

498.16

in speed if i were to take this same

499.84

query

501.28

and i could

503.199

if i did this query with the where

506.72

that one that did work

508.639

you know that one only gave me the three

510.56

but if i used that along with the one

513.279

that was the inner join where was the

516.24

inner join

517.519

um

520.56

that's left joint here if i do that same

522.56

one so you can see here

525.12

these are the identical result sets

527.92

and for all these are identical

531.2

queries

532.48

i guess as far as like this is what i'm

534.32

asking but how i ask it is different

537.6

and in a lot of cases a lot of modern

540.24

databases you will find

542.08

that using the inner join approach like

544.48

this is going to be substantially faster

547.279

i have seen

549.04

a pretty nice percentage uh as

552.24

as far as like set up to like 70 and 80

554.24

percent

555.6

better running

557.2

queries and maybe even more than that

559.76

doing it with

561.2

this inner join this inner join as

563.279

opposed to doing like the multiple table

565.04

listing

567.12

and it also it helps with

569.36

it we'll get into in

571.6

the idea of indexes and stuff like that

573.6

but

574.8

this is going to be just showing you

576.88

this so that you can see it but you want

579.36

to use this this inner join approach

582.56

so now

583.92

let's go back over here now let's go

585.6

ahead

587.2

and i'm going to create a new table this

590.48

third table i'm going to create

592.8

i'm going to call it lookup type or lkp

594.88

type

596.72

and what you can see here

598.48

is all it is is it's a type id

601.2

it's a 100 up to 100 character name i'm

604

going to default it to undefined i'm

605.92

going to have a code that's a varchar4

608.56

and then its primary key is type id

611.12

and so now i'm going to because i

613.279

cheated a little bit earlier i have

615.2

somewhere in here

617.519

some sql to create a few rows

623.68

so i'm going to create those rows

628.959

and whatever i did i didn't do right so

630.88

let's go back to this

632.399

it's called lookup type

634.88

oh that's not insert into table

641.12

that's what happens when you don't

642.16

pre-run your stuff but that's okay at

644.56

least i'm saving us a little bit of time

646.8

and okay and then if i do select star

650

from lookup type

654

then i'm going to see the three records

655.44

i created with their id so now i've got

657.76

this idea of a home address a mailing

659.279

address and a business address and what

661.279

i'm going to do is i'm going to go into

664.56

tutorial 1 table where we see our

666.959

addresses and i'm going to add a type

669.279

a type field

672

because we're going to get a little more

673.68

complicated here so first thing i'm

675.6

going to do is i'm going to add a column

677.92

so i'm adding a column called type id

680.72

to tutorial 1 and it's going to show up

682.72

after zip so now if i do describe

686.16

tutorial 1. i'm going to see that i have

689.12

now this type id

691.2

and by default it's null and if i do

694

this

694.88

select star from tutorial 1

699.279

then i'm going to see that i have the

701.36

type id of null everywhere

704.32

now let's just make it simple

706.56

and

708.079

i'm going to update

711.44

well let's do it this way first now what

713.36

i'm going to do is if you can remember

715.519

we used a reference in the past we used

718.639

a foreign key reference uh

722

we use this constraint in order to tie

726.16

a address essentially what an address is

729.04

back to a person

731.6

and so we're going to do the same thing

732.72

but we're going to use an alter

734.399

so what we can do

736.079

is we can alter the table

739.279

and i'll show you here

741.04

is oops

742.48

i have a typo in there anyways so i'm

744.399

going to come in like we saw before i'm

745.839

going to alter table i'm going to give

747.279

it a table name so this is going to be

748.72

that tutorial 1 table

750.88

and now i'm going to add a constraint

752.959

before we added a column

755.6

i'm going to give it the constraint name

757.44

what type is it

759.04

and then basically you know what key or

762.399

what com what column which would be type

764.959

id am i using

767.2

in tutorial one and then what am i tying

769.279

it off to i'm going to tie it to lookup

770.639

type type id

773.92

i get it

775.68

there we go

776.639

and so now

779.44

going back to my type ids if i wanted to

782

update

783.76

tutorial 1.

787.68

and i want to set the type id

790.88

equal to 4 let's do that because look

793.68

there is we'll note that there is no 4

795.519

so it should complain as you remember

797.36

because that foreign key is going to

798.399

kick off here in a second and sure

800.639

enough

803.76

foreign key constraint fails

806.48

uh

807.6

the type fk and that's the name of the

810

that's my foreign key and it does

812.16

because i can't find number four in

814.56

there but if i change it over to three

817.04

then boom

818.48

i've got it and if i go select star from

821.04

tutorial one now everybody's type is

823.44

going to be type three

825.04

which is a business address

829.76

so now if we had now we've got three

831.279

tables and so that's where i want to go

833.6

next is i'm going to take

836.959

our earlier one

841.6

let's do this

845.76

get my notes changed a little bit

848.24

and i will show you this

850.8

a little better in a bigger

852.959

font

854.079

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

855.6

to actually do two inner joins

859.519

it's i'm going to interjoin

862.24

the table lookup type

867.04

and i'll call him

869.76

and i'm going to join that on lt dot

874.48

type id equals

877.519

he is in tutorial 1

880.16

which is t1 type id

883.36

and so now all i'm going to do is i'm

885.36

just going to take

886.8

after all of this

888.639

i'm going to come in here i'm going to

889.76

do an lt dot

891.519

uh we'll do that code for now

896.32

and so if we take that and we jump over

898

in our database

899.44

so no this is i haven't changed too much

901.6

is i'm saying i'm going to add another

903.36

table that i'm going to link data to

906.56

and i'm only going to show just one

908.079

additional

909.199

field

910.959

and so doing that

912.56

now i see

913.839

that i have my

916.399

where is it i have my

919.36

tutorial parent data

921.76

now i can see my tutorial child data

924.88

and now i can see

927.36

my lookup type

929.279

and i could change that so i could call

930.959

it instead of

933.68

uh oh wow let's do it this one that's

936.24

it'll be easier to edit it here so let's

938.079

say instead of code i say name

942

and i can make either of these a left

943.759

join so i come in here and do a left

944.959

join

948.079

and i can do this and make this a left

950

join

951.36

we'll make both of them and then you're

953.199

going to see

954.399

that it'll be able to flow through

957.199

and

958.079

i see nulls across the board

960.88

here

962.56

now

963.6

if i were to do an inner join on this

965.6

first one the inner join back to the

967.759

address

968.8

then this row would disappear because it

971.12

would say i have to have

973.6

an address but now

976.32

if i do an inner join

980.399

here

981.44

but leave a left join for the type

984.959

i'm sorry leave a left join

988.56

and then do an inner join on the type

992.399

then i'm also going to lose it

995.44

we'll see here

997.6

because

998.72

even though i did a left join for the

1001.36

address i said were said hey give me

1004.16

nulls if you know if you find nulls

1006.079

that's fine

1007.36

but

1008.72

i came back with the inner join and said

1011.92

i have to have a matching name

1016

and so now

1017.199

i'm stuck because it says hey i'm

1018.72

looking up the code

1020.32

you gave me a null i can't find the null

1022.399

code anywhere so that's not going to

1023.92

work

1025.199

and so you can you know mix and match

1026.959

your inner joins and left joins but

1030.799

realize that once you do one that's

1032.799

entered you're going to restrict some of

1034.24

your some of the data that comes back

1037.52

so it can be a little bit

1039.679

complicated

1041.6

and that's why i wanted to get us to at

1043.12

least three tables now if we want to

1045.12

take our earlier example

1047.67

[Music]

1049.52

i'll show you how it gets really

1050.799

complicated quick if we do our

1053.919

one with the commas

1056.64

uh

1060.72

that's the inner join

1062.559

where did i put that

1064.64

nope not that one

1073.76

let's create table

1075.76

it's another

1078

here we

1078.84

go so let's take our earlier one

1084.08

where we did the comma version so we did

1087.36

so we do a select from table 1 comma

1090.64

table 2

1092.84

comma

1094.799

table three lookup type

1097.52

lt

1098.96

now

1100

if we want to do the inner join we're

1101.28

going to say where

1104.799

the t1 ids match and

1108.64

lt dot

1111.2

code id or type id

1116.28

equals was that t1

1119.2

dot type id

1124.88

and so you end up having these really

1126.64

huge

1128

where clauses yep there we go and so i

1130.16

just pasted that in

1132.08

and you have these really huge where

1133.44

clauses but i do get the right data it's

1135.2

just now

1138

which is basically a processing thing

1140

it's now it's

1141.12

basically pulling everything and then

1143.28

it's going to start pulling it out as

1145.12

opposed to

1146.4

while it's pulling data limiting what

1148.16

it's pulling even in the first

1150

essentially like the first pass

1152.88

now

1154.24

i think that's a good spot for us to

1156.24

stop on this one we've added a third

1158

table we've got some additional data

1160.48

and we're cruising along learning a

1162.24

little bit more about our you know our

1164.48

selects

1165.6

we've touched on some updates and things

1167.12

like that

1168.16

and so now we're going to get we'll

1170.16

continue moving on the next episode that

1173.36

being said we'll wrap this one up so go

1175.28

out there and have yourself a great day

1176.88

a great week and we will talk to you

1179.84

next time

1196.08

you