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.
Related
I have one problem with my SELECT query in my blog page.
I want comment count of each blog when comment status=1.
I am apply following query..
SELECT CONCAT(u.first_name," ",u.last_name) name, r.*,
IF(c.status=1,COUNT(c.id)) as comment
FROM users u
RIGHT JOIN resources r ON u.id = r.created_by
LEFT JOIN comments c ON r.id = c.resource_id
WHERE r.type = 1
AND r.status=1
GROUP BY r.id
ORDER BY r.created_date DESC
LIMIT 0,5
but it giving SYNTAX ERROR..
Error: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your
SQL syntax; check the manual that corresponds to your MariaDB server version for the right
syntax to use near ') as comment FROM users u RIGHT JOIN resources r ON u.id = r.created_by
LEFT JOI' at line 1
Please tell me where I am wrong.
Thanks
If statement contains three expressions. First, the expression, second the value returned if condition is true and third if condition is false so you are missing the third expression.
Try the below code
SELECT CONCAT(u.first_name," ",u.last_name) name,r.*,IF(c.status=1,COUNT(c.id), 0) as comment
FROM users u RIGHT JOIN resources r ON u.id = r.created_by
LEFT JOIN comments c ON r.id = c.resource_id
WHERE r.type = 1
AND r.status=1
GROUP BY r.id
ORDER BY r.created_date DESC
LIMIT 0,5
Select concat(u.first_name," ",u.last_name) name,r.*,
case when c.status=1 then COUNT(c.id) end as comment
FROM users u RIGHT JOIN resources r ON u.id = r.created_by
LEFT JOIN comments c ON r.id = c.resource_id
WHERE r.type = 1
AND r.status=1
GROUP BY r.id
ORDER BY r.created_date DESC
LIMIT 0,5
https://www.w3schools.com/sql/func_mysql_case.asp
if function requires 3 parameters to be passed to it. IF(expression ,expr_true, expr_false) is how it should be used.
Have a look at https://www.w3resource.com/mysql/control-flow-functions/if-function.php
I have the following query:
SELECT s.username FROM `instagram_shop` s
INNER JOIN `instagram_shop_picture` p
ON s.id = p.shop_id
WHERE s.`deletedAt` IS NULL
HAVING COUNT(p.id) = 0
GROUP BY s.id
and I keep getting the following 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 'GROUP BY s.id LIMIT 0, 30' at line 6
What is the issue here?
Move the HAVING clause after the GROUP BY clause.
MySQL is very specific about the order of keywords/clauses in a SELECT statement
Reference: 13.2.9 SELECT Syntax https://dev.mysql.com/doc/refman/5.6/en/select.html
Try the below one :
there is an syntax issue with your query,
Having should follow after GROUP BY caluse.
Also the columns which you mention in your GROUP BY
clause should be present in the SELECT list.
SELECT s.id,s.username FROM `instagram_shop` s
INNER JOIN `instagram_shop_picture` p
ON s.id = p.shop_id
WHERE s.deletedAt IS NULL
GROUP BY s.id,s.username
HAVING COUNT(s.id) = 0
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 have three tables A B C and i'm trying to retrieve information from all three.
A has the columnns userid avatar username and B has the column postid, dateshared and C has the column commenter postid datecommented.
I'm trying to run the query
Select C.comment, C.commenter, C.datecommented, B.postid, B.dateshared A.username A.avatar from B Left Join C Left join A on C.postid = B.postid AND A.userid = C.commenter where B.postid IN ('1','2','3') order by C.dateshared desc
but it gives the following 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 'where B.postid IN ('1', '2', '3') order by C.dateshared '
Can anyone point out what I'm doing wrong or suggest how to go about it?
Each LEFT JOIN requires its own ON condition:
SELECT C.comment, C.commenter, C.datecommented, B.postid, B.dateshared, A.username A.avatar
FROM B
LEFT JOIN
C
ON C.postid = B.postid
LEFT JOIN
A
ON A.userid = C.commenter
WHERE B.postid IN ('1','2','3')
ORDER BY
C.dateshared desc
This should work for you, your query had some syntax errors:
Select C.comment,C.commenter,C.datecommented,B.postid,B.dateshared,A.username,A.avatar
from B
Left Join C on C.postid = B.postid
Left join A on A.userid = C.commenter
where B.postid IN ('1','2','3')
order by C.dateshared desc
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!