last day (88 days later) » 

15:17
hi
okay so, do you remember our talk about the query?
i remember us discussing it but i never really grasped the query
okay, maybe i can refresh your memory a little. i wast to pull all information from multiple tables using 1 id
so here is an example of doing it wrong
`SELECT merchants.id, company_name, merchants.email, merchants.fname, merchants.lname, merchants.phone, date_added,
viewable_merchant.fname, viewable_merchant.lname, website, picture,
address, city, state, zip, country, is_shipping
FROM users, address, viewable_merchant
WHERE merchants.id = :id AND address.f_id = :id and is_user = 0 LIMIT 1`
ok
you need to also set your primary/ foreign key relationship in the where clause
or do the join
where you say
inner join address on merchants.id = address.merchant_id
i can't do relationships in the engine i am running my db on
15:23
it doesnt matter
if you dont set it in the query you should get a lot of info you dont need
cuz its going to pull everythign
the issue is
can you write the query out? idc about the fields, just after the where
the where clause just meaning
where merchants.id = address.merchants_id
i want to pull all of the information from merchants, viewable_merchant and address
give me a list of tables their columns and then tell me what u want
but if the merchant doesnt have an address i want it to still pull from the other two tables
15:25
yeah i remmeber that part
ok
|----merchants-----|
id -pk
company_name
email
fname
lname
phone
date_added
|-----address-----|
id- pk
f_id -fk
address
city
state
zip
country
is_user
|-----viewable_merchant-----|
id - pk
merch_id -fk
email
fname
lname
website
picture
you can use table.* idc
15:43
ok so try this...
oh, the anticipation
SELECT m.*, v.fname, v.lname, v.website, v.picture, a.address, a.city, a.state, a.zip, a.country, a.is_user FROM address a INNER JOIN merchants m On a.f_id = m.id JOIN viewable_merchant v on m.id = v.merch_id where is_user = 0 Limit 1
the a v and m are just aliases but they make it easier to read for me
where do you specify the actual id?
oh yeah
change the where to say
WHERE m.id = :id and is_user = 0
if they dont have an address f_id that will return 0
that doesnt work properly.. i will just keep researching on how to do it
thanks for the direction :]
16:00
you tried it?
try just doing Join and not Inner Join
@carrie
MySQL returned an empty result set (i.e. zero rows). ( Query took 0.0003 sec )
Full outer join produces the set of all records in Table A and Table B, with matching records from both sides where available. If there is no match, the missing side will contain null.
hang on a sec
"case when a.f_id is not null then 'Address' else '' end as Address"
but that in the select part where you are trying to get the address
i dunno if it will work but we use it for when they dont have a middle name
@carrie
did that help at all?
u might have to adjust syntax cuz we are using sql server of course :)
16:15
i worked it out
wanna see?
sure thing love
:)
and good job!!
SELECT *
FROM merchants AS m
LEFT OUTER JOIN viewable_merchant AS v ON m.id = v.merch_id
LEFT OUTER JOIN address AS a ON m.id = a.f_id
WHERE m.id = :id
UNION
SELECT *
FROM merchants AS m
RIGHT OUTER JOIN viewable_merchant AS v ON m.id = v.merch_id
RIGHT OUTER JOIN address AS a ON m.id = a.f_id
WHERE m.id = :id
LIMIT 0 , 30
this imitates the outer full join and returns NULL where it doesnt match
very good :)
i got to figure out the is_user
STS :)
16:17
sts?
could i do LEFT OUTER JOIN address AS a ON m.id = a.f_id AND is_user = 0 ?
@panda
SELECT *
FROM merchants AS m
LEFT OUTER JOIN viewable_merchant AS v ON m.id = v.merch_id
LEFT OUTER JOIN address AS a ON m.id = a.f_id and is_user = 0
WHERE m.id =:id
UNION
SELECT *
FROM merchants AS m
RIGHT OUTER JOIN viewable_merchant AS v ON m.id = v.merch_id
RIGHT OUTER JOIN address AS a ON m.id = a.f_id and a.is_user = 0
WHERE m.id = :id
SUCCESSSSSS
woohoo
that helps me understand joins more along with this link
16:33
k
k thanks ttyl
16:46
ok <3 u

  last day (88 days later) »