error with MySQL SQL syntax - mysql

Why do I always get a syntax error on the following inner join:
SELECT 'myapp_instagram_shop'.id
FROM 'myapp_instagram_shop'
INNER JOIN 'myapp_instagram_shop_picture'
ON 'myapp_instagram_shop'.id = 'myapp_instagram_shop_picture'.shop_id;
Error is:
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 ''myapp_instagram_shop'
INNER JOIN 'myapp_instagram_shop_picture' ON 'sh' at line 1

try
SELECT myapp_instagram_shop.id FROM myapp_instagram_shop INNER JOIN myapp_instagram_shop_picture ON myapp_instagram_shop.id = myapp_instagram_shop_picture.shop_id;

Related

Getting syntax error using WITH (Common Table Expressions) in mysql 8

I am using mysql 8.0.21. I am trying to execute this statement:
WITH t
AS (SELECT h.store_hsh,
Avg(s.sales) AS SALES_AVG,
Avg(s.customers) AS CSTMR_AVG
FROM sat_day_facts s
INNER JOIN link_day l
ON s.link_day_hsh = l.link_day_hsh
INNER JOIN hub_store h
ON h.store_hsh = l.store_hsh
GROUP BY h.store_hsh)
SELECT t.store_hsh,
Now() AS LOAD_DATETIME,
Now() AS LOAD_END_DATETIME,
t.sales_avg,
t.cstmr_avg,
(SELECT 1 + Count(*)
FROM t t1
WHERE t1.sales_avg > t.sales_avg) AS SALES_RANK;
but I keep having this error
ProgrammingError: 1064 (42000): 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 'WITH t as (select h.STORE_HSH, AVG(s.SALES) as SALES_AVG , AVG(s.CUSTOMERS) as' at line 1
I checked the manual of SQL but still don't understand what is going wrong.
Does anyone could help?

Error Code: 1064. You have an error in your SQL syntax;

When I execute this query
SELECT
*
FROM
user
INNER JOIN friend
ON user.user_id = friend.friend_id
WHERE friend.user_id = :userId
ORDER BY user.firstName ASC
I get this error:
Error Code: 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 ':userId ORDER BY user.firstName ASC' at line 7
I think you are trying PHP's PDO query directly in mysql, but mysql couldn't get it, Try to replace :userId by actual value you want to compare,

Error on my mysql query string

I got an error like this "Additional information: 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 " when i running my code.Iam using webapi
string query = "SELECT `theatredetails`.*,`location`.`LocationName,`moviemaster`.`MovieMasterId`,`moviemaster`.`MovieName`,`moviemaster`.`Image` FROM `theatredetails` INNER JOIN `location` ON `theatredetails`.`LocationId`=`location`.`LocationId` INNER JOIN `moviemaster` ON `moviemaster`.`TheatreDetailsId`=`theatredetails`.`TheatreDetailsId`";
Iam using 3 inner joins,is there any error on my query?
You forgot a backtick
`location`.`LocationName
^---here

MySQL Error - Join tables from two different databases

MySQL query
select s.site_id,s.site_name,u.username
FROM cloud_search.dbo.site_request s join user_db.dbo.user_info u
on u.user_id=s.site_id;
Error
ERROR 1064 (42000): 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 '.site_request s join user_db.dbo.user_info u on u.user_id=s.site_id' at line 1
What am i doing wrong here..?
Are you sure you're using dbo it's usually for MSSQL
It's probably
select s.site_id,s.site_name,u.username FROM cloud_search.site_request s join user_db.user_info u on u.user_id=s.site_id;

What is wrong with this MySQL query? right syntax for INNER_JOIN WHERE clause?

SELECT core_student.STUDENT_ID, core_student.FIRST_NAME, core_student.LAST_NAME
FROM `core_student`
INNER_JOIN `ssp_student`
WHERE ssp_student.STUDENT_ID = core_student.STUDENT_ID;
throws an error on the WHERE clause:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to user near 'ssp_student' WHERE ssp_student.STUDENT_ID = core_student.STUDENT_ID
I just want to select the fields listed in the SELECT, then join all columns from ssp_student where the ssp_student.STUDENT_ID field is the same as the core_student.STUDENT_ID field.
Correct way is
SELECT core_student.STUDENT_ID, core_student.FIRST_NAME, core_student.LAST_NAME
FROM `core_student`
INNER JOIN `ssp_student`
on ssp_student.STUDENT_ID = core_student.STUDENT_ID;