sql - Mysql statement (syntax error on FULL JOIN) -
what wrong sql statement, says problem near full join, i'm stumped:
select `o`.`name` `offername`, `m`.`name` `merchantname` `offer` `o` full join `offerorder` `of` on of.offerid = o.id inner join `merchant` `m` on o.merchantid = m.id group `of`.`merchantid`
please gentle, not sql fundi
mysql doesn't offer full join, can either use
- a pair of left+right , union; or
- use triplet of left, right , inner , union all
the query wrong, because have group select columns not aggregates.
after convert left + right + union, still have issue of getting offername , merchantname random record per each distinct of.merchantid
, , not same record.
because have inner join condition against o.merchant, full join not necessary since "offerorder"
records no match in "offer"
fail inner join. turns left join (optional). because grouping on of.merchantid
, missing offerorder
records grouped under "null" merchantid.
this query work, each merchantid, show 1 offer merchant made (the 1 first name when sorted in lexicographical order).
select min(o.name) offername, m.name merchantname offer o left join offerorder `of` on `of`.offerid = o.id inner join merchant m on o.merchantid = m.id group `of`.merchantid, m.name
note: join o.merchantid = m.id
highly suspect. did mean of.merchantid = m.id
? if case, change left right join.
Comments
Post a Comment