Can someone please suggest a solution for this Sql error - mysql

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 'Outer Join Mobile ON Plan.PlanName = Mobile.PlanName Where Mobile.PlanName IS NU' at line 3
Select PlanName
From Plan
full Outer Join Mobile
ON Plan.PlanName = Mobile.PlanName
Where Mobile.PlanName IS NULL;

You don't have FULL JOINS on MySQL, but you can emulate them.
SELECT * FROM plan
LEFT JOIN mobile ON plan.id = mobile.id
UNION
SELECT * FROM plan
RIGHT JOIN mobile ON plan.id = mobile.id
Also, you can use left join, right join, left outer join, right outer join, inner join based on your requirements.

Related

mysql update with several joins

I would like to update with 2 join.... but :
UPDATE glpi.glpi_users
FROM
glpi.glpi_groups_users
INNER JOIN glpi.glpi_groups ON glpi.glpi_groups_users.groups_id = glpi.glpi_groups.id
INNER JOIN glpi.glpi_users ON glpi.glpi_users.id = glpi.glpi_groups_users.users_id
SET glpi.glpi_users.id = 2
WHERE
glpi.glpi_groups.`name` LIKE 'technique'
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 'FROM
glpi.glpi_groups_users
INNER JOIN glpi.glpi_groups ON glpi.glpi_groups_us' at line 2
Time: 0s
thanks for your help
I think that the syntax you want is:
UPDATE glpi.glpi_users u
INNER JOIN glpi.glpi_groups_users gu ON gu.users_id = u.id
INNER JOIN glpi.glpi_groups g ON g.id = gu.groups_id
SET u.id = 2
WHERE g.name = 'technique'
That is: MySQL update/join syntax doesn't have a FROM clause - it looks like UPDATE ... JOIN ... SET ... WHERE ....
Notes:
since no wildcards do appear in the right side operand, name LIKE 'technique' is equivalent to name = 'technique'
table aliases make the query easier to write and read

Error when executing a FULL OUTER JOIN query in MySQL [duplicate]

This question already has answers here:
How can I do a FULL OUTER JOIN in MySQL?
(15 answers)
Closed 5 years ago.
Hello I am trying to execute a query in mysql but i am getting following error
query :-
SELECT * FROM user_registration FULL OUTER JOIN user_details ON user_registration.email = user_details.gmail
error is :
#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 'OUTER JOIN dreams ON user_registration.email = user_details.gmail LIMIT 0, 25' at line 1
As there is no full outer join in MySQL, you can use left and right outer joins with union:
select * from user_registration ur left join user_details ud on ur.email = ud.gmail
union
select * from user_registration ur right join user_details ud on ur.email = ud.gmail

Mysql error saying "an expression was expected near FROM"

SELECT users.name,
phone_info.phone_num,
FROM users LEFT OUTER JOIN phone_info
ON users.user_id = phone_info.user_id
I have 2 tables in my db users and phone_info. I want to use left join to execute the users who have numbers. However I get an error like this
Static analysis:
1 errors were found during analysis.
An expression was expected. (near "FROM" at position 43)
SQL query: Documentation
SELECT users.name, phone_info.phone_num, FROM users LEFT JOIN phone_info ON
users.user_id = phone_info.user_id
MySQL said: Documentation
#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
'FROM users LEFT JOIN phone_info
ON users.user_id = phone_info.user_id' at line 3
Get rid of the extra comma before FROM
SELECT users.name,
phone_info.phone_num
FROM users LEFT OUTER JOIN phone_info
ON users.user_id = phone_info.user_id
SELECT users.name,
phone_info.phone_num
FROM users LEFT OUTER JOIN phone_info
ON users.user_id = phone_info.user_id ;I just removed that extra comma .try now I should work
The error explains it self.
An expression was expected. (near "FROM" at position 43);
Because you have entered a comma(,) MySQL expects an expression after that. Just remove it.
Here's the query;
SELECT users.name,
phone_info.phone_num
FROM users LEFT OUTER JOIN phone_info
ON users.user_id = phone_info.user_id;

Query error when testing in Database SQL

I have this query and appearently it's faulty?
I'm trying to join fices with mems so I can have the ficeID along with all the results from mems(These queries work individually). What am I doing wrong?
SELECT *
FROM mems
WHERE deleted <> -1
ORDER BY sort_mems
LEFT JOIN SELECT ficeID
FROM fices
Result:
#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 'LEFT JOIN SELECT ficeID FROM offices LIMIT 0, 30' at line 1
You have JOIN clause after ORDER BY. You should place it in FROM.
I suggest you define condition of a LEFT JOIN
Also, I suggest you surround you temp tables with brackets:
SELECT m.*, t1.officeID
FROM members m
LEFT JOIN offices t1
ON m.memberID = t1.memberID
WHERE m.deleted <> -1
ORDER BY m.sort_membername;
Yes, you have the LEFT JOIN in the wrong spot (it should go after your FROM clause, and you also seem to be missing a join criteria (the ON part, this tells the database how these tables are related):
SELECT *
FROM mems m
LEFT JOIN fices f
ON m.??? = f.???
WHERE deleted <> -1
ORDER BY sort_mems

How can isolve Mysql Error: Code: 1064

I tried to run the following query to select all of the lines respecting the join criteria, then adds all the rows in the table "client" and the table "commande" that were rejected because they did not meet the join criteria.
Query:SELECT * FROM CLIENT c FULL JOIN commande com ON c.id_client=com.id_client
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 'FULL JOIN commande com on c.id_client=com.id_client
LIMIT 0, 1000' at line 1
MySQL unfortunately does not support FULL JOIN. You can achieve the same results with a UNION and an OUTER JOIN though:
SELECT c.*, com.*
FROM CLIENT c
LEFT JOIN commande com ON c.id_client=com.id_client
UNION
SELECT c.*, com.*
FROM commande com
LEFT JOIN CLIENT c ON com.id_client=c.id_client
Simplified SQL Fiddle Demo
Also, consider defining your fields being returned versus returning all.
try to use full outer join or full inner join
try USING:
SELECT * FROM `CLIENT` FULL JOIN commande com USING (id_client) […];