Maybe a facepalm for you guys, but as a SQL query newbie, I'm having a syntax issue. Anyone know what's wrong?
SELECT * FROM company C
OUTER JOIN company_address A ON C.company_id = A.company_id
WHERE A.company_id IS NULL
Giving the error:
#1064 - You have an error in your SQL syntax; check the manual that corresponds
to your MySQL server version for the right syntax to use near
'OUTER JOIN company_address A ON C.company_id = A.company_id WHERE A.address_id
' at line 2
In MySQL you should use LEFT OUTER JOIN or RIGHT OUTER JOIN. There is no just OUTER JOIN. If you need FULL OUTER JOIN in MySql you can use UNION of LEFT JOIN and RIGHT JOIN
Try
SELECT * FROM company C
LEFT JOIN company_address A ON C.company_id = A.company_id
WHERE A.company_id IS NULL
You have to write LEFT JOIN,RIGHT JOIN,INNER JOIN or FULL OUTER JOIN instead of only OUTER JOIN.
There is also one error with your table name there shouldn't be space between the letters of a table like this [company C- it should be named as company_C]
I hope that will be work..All the best!
Related
I've got the following SQL query and I'm trying to implement pagination, so I first want to get the COUNT of the result:
The normal query (works fine)
SELECT DISTINCT c.*, p1.*, username FROM candidate c
LEFT JOIN note p1 ON (c.candID = p1.candidateID)
LEFT JOIN user ON p1.userID = user.id
LEFT OUTER JOIN note p2 ON
(c.candID = p2.candidateID AND (p1.noteID < p2.noteID))
WHERE p2.candidateID IS NULL ORDER BY c.firstname ASC
I've tried the following, but it throws an error and I'm not sure what correct syntax to use:
Attempting to count the results (doesn't work)
SELECT COUNT(DISTINCT c.*, p1.*, username) FROM candidate c
LEFT JOIN note p1 ON (c.candID = p1.candidateID)
LEFT JOIN user ON p1.userID = user.id
LEFT OUTER JOIN note p2 ON
(c.candID = p2.candidateID AND (p1.noteID < p2.noteID))
WHERE p2.candidateID IS NULL ORDER BY c.firstname ASC
The error:
Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ', p1., username) FROM candidate c LEFT ' at line 1
One option is to use a subquery:
SELECT COUNT(*)
FROM (
SELECT DISTINCT c.*, p1.*, username FROM candidate c
LEFT JOIN note p1 ON (c.candID = p1.candidateID)
LEFT JOIN user ON p1.userID = user.id
LEFT OUTER JOIN note p2 ON
(c.candID = p2.candidateID AND (p1.noteID < p2.noteID))
WHERE p2.candidateID IS NULL
) t
Depending on your data, you may be able to do this without the subquery, but you cannot use multiple columns with the count aggregate -- that's what is causing your error.
I need to replicate following where condition in Oracle to mysql.. I have also written my version of mysql query and I am having trouble writing left outer join part (I need to perform left outer on voters and join with nodes. Can someone please help?
Oracle equivalent:
WHERE B.nid=C.nid
AND B.uid = D.uid
and D.nid(+)= E.nid
Mysql query
select
C.ccc
,D.dewde
from
USERS B
inner join
ACCOUNT_GROUP_INFO C on (B.nid = C.nid)
inner join
VOTERS D on (B.uid = D.uid)
left outer join
NODES E on (D.nid = E.nid)
Can someone please help me with the query?
I am getting the following Error
064 - You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use
near 'from catalog_product_flat_1 a inner join
catalog_product_entity c on a.sku' at line 3
when I try out the below query on phpmyadmin
update a
set a.small_image = b.value
from `catalog_product_flat_1` a
inner join `catalog_product_entity` c
on a.sku = c.sku
inner join `catalog_product_entity_media_gallery` b
on b.entity_id = c.entity_id
I also tryout without using alias but still same issue
The SET clause comes after the JOIN clauses:
UPDATE `catalog_product_flat_1` a
inner join `catalog_product_entity` c
on a.sku = c.sku
inner join `catalog_product_entity_media_gallery` b
on b.entity_id = c.entity_id
SET a.small_image = b.value
See the documenation:
http://dev.mysql.com/doc/refman/5.5/en/update.html
I used a query like
select a.email,b.vuid
from user a
,inner join group b on a.uid = b.uid
where a.email='xx#xx.de' and a.kid=1 and b.vid=29
limit 1
but I always get this error.
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'inner join group b on a.uid = b.uid where a.email='xx#xx.de' at line 1
I think its because the inner join but I don't know really.. Could someone help me?
Remove the , after from user a.
Your query should be:
select a.email,b.vuid
from user a
inner join group b
on a.uid = b.uid
where a.email='xx#xx.de'
and a.kid=1
and b.vid=29
limit 1
select a.email,b.vuid from user as a inner join group as b on ...
Of course you can omit the as keyword as demonstrated by #FrustratedWithFormsDesigner but in my opinion it is much more readable this way.
What's wrong with this code?
FROM product_tag, ps_product_tags_all
LEFT JOIN users ON
users.id = product_tag.lang
LEFT JOIN images ON
images.id = ps_product_tags_all.lang
Error:
Unknown column 'product_tag.lang' in 'on clause'
You are mixing implicit and explicit joins and joining in the wrong order. Try this:
SELECT *
FROM ps_product_tags_all
LEFT JOIN images ON
images.id = ps_product_tags_all.lang, product_tag
LEFT JOIN users ON
users.id = product_tag.lang
WHERE ...
Remember that explicit JOIN has higher precedence than the implicit join from using comma. To avoid this error I would recommend that you always use explicit joins:
SELECT *
FROM ps_product_tags_all
LEFT JOIN images ON images.id = ps_product_tags_all.lang
LEFT JOIN product_tag ON ...
LEFT JOIN users ON users.id = product_tag.lang
This is not syntax error, but structure error - you don't have "lang" column in "product_tag" table.