Outline ·
[ Standard ] ·
Linear+
Mysql says "unknown column" when doing full join
|
TSseiferalmercy
|
Sep 16 2020, 09:54 PM, updated 6y ago
|
Getting Started

|
So I executed this command:
select* from customer full.join orders on customer.ID = orders.customerid;
it gave me this error "error 1054 unknown column 'customer.ID' in 'on clause'
The strange thing is, when I execute the same set of commands for an inner join, it works just fine.
|
|
|
|
|
|
narf03
|
Sep 16 2020, 10:39 PM
|
|
What's that dot for between full join? https://www.codeproject.com/Articles/33052/...on-of-SQL-JoinsThis post has been edited by narf03: Sep 16 2020, 10:42 PM
|
|
|
|
|
|
TSseiferalmercy
|
Sep 16 2020, 10:49 PM
|
Getting Started

|
QUOTE(narf03 @ Sep 16 2020, 10:39 PM) Thanks, I removed the dot, same problem.
|
|
|
|
|
|
ketnave
|
Sep 16 2020, 10:52 PM
|
|
Already suggested before, post to sqlfiddle ... it will be easier for others to help.
|
|
|
|
|
|
jackoats.my
|
Sep 17 2020, 08:32 PM
|
Getting Started

|
QUOTE(seiferalmercy @ Sep 16 2020, 10:49 PM) Thanks, I removed the dot, same problem. Try this on Oracle SQL. Might be diff for other variants CODE select* from customers full outer join orders on customers.customerID = orders.customerID;
This post has been edited by jackoats.my: Sep 17 2020, 08:34 PM
|
|
|
|
|
|
jackoats.my
|
Sep 17 2020, 08:38 PM
|
Getting Started

|
Is there a column called ID in your customer table? >>>unknown column 'customer.ID' QUOTE(seiferalmercy @ Sep 16 2020, 09:54 PM) So I executed this command: select* from customer full.join orders on customer.ID = orders.customerid; it gave me this error "error 1054 unknown column 'customer.ID' in 'on clause' The strange thing is, when I execute the same set of commands for an inner join, it works just fine. This post has been edited by jackoats.my: Sep 17 2020, 08:38 PM
|
|
|
|
|
|
jackoats.my
|
Sep 17 2020, 08:50 PM
|
Getting Started

|
FULL OUTER JOIN is equivalent to LEFT OUTER JOIN UNION RIGHT OUTER JOIN So you can also try the above step if the FULL OUTER JOIN doesn't work. QUOTE(seiferalmercy @ Sep 16 2020, 09:54 PM) So I executed this command: select* from customer full.join orders on customer.ID = orders.customerid; it gave me this error "error 1054 unknown column 'customer.ID' in 'on clause' The strange thing is, when I execute the same set of commands for an inner join, it works just fine.
|
|
|
|
|
|
TSseiferalmercy
|
Sep 17 2020, 09:00 PM
|
Getting Started

|
QUOTE(jackoats.my @ Sep 17 2020, 08:38 PM) Is there a column called ID in your customer table? >>>unknown column 'customer.ID' yes there is very strange...
|
|
|
|
|
|
jackoats.my
|
Sep 17 2020, 09:07 PM
|
Getting Started

|
There is nothing strange about it. If there's actually no intersections between the two tables, then there will be no outer join. The error message might be telling you that. But then you're saying there is an inner join between the two tables... So there could a typo when you change from inner join to full outer join, or syntax error if MySQL does not support the syntax FULL JOIN. QUOTE(seiferalmercy @ Sep 17 2020, 09:00 PM) yes there is very strange... This post has been edited by jackoats.my: Sep 17 2020, 09:14 PM
|
|
|
|
|
|
bumpo
|
Sep 18 2020, 11:02 AM
|
|
ts, you sure you are using mysql?
last i checked mysql dont support FULL JOIN and needs to be written as below to achieve it . UNION vs. UNION ALL depends on the outcome you're looking for
SELECT * FROM A LEFT JOIN B ON A.key = B.key
UNION
SELECT * FROM A RIGHT JOIN B ON A.key = B.key
|
|
|
|
|
|
TSseiferalmercy
|
Sep 18 2020, 11:10 AM
|
Getting Started

|
QUOTE(bumpo @ Sep 18 2020, 11:02 AM) ts, you sure you are using mysql? last i checked mysql dont support FULL JOIN and needs to be written as below to achieve it . UNION vs. UNION ALL depends on the outcome you're looking for SELECT * FROM A LEFT JOIN B ON A.key = B.key UNION SELECT * FROM A RIGHT JOIN B ON A.key = B.key yes I am. I’m new to this, so a lot of syntax I dont know.
|
|
|
|
|
|
bumpo
|
Sep 18 2020, 11:18 AM
|
|
QUOTE(seiferalmercy @ Sep 18 2020, 11:10 AM) yes I am. I’m new to this, so a lot of syntax I dont know. interestingly enough when using FULL JOIN, mysql complains about unknown column but when infact it doesnt support it your best bet is to rewrite it using UNION/UNION ALL
|
|
|
|
|
|
TSseiferalmercy
|
Sep 18 2020, 11:26 AM
|
Getting Started

|
QUOTE(bumpo @ Sep 18 2020, 11:18 AM) interestingly enough when using FULL JOIN, mysql complains about unknown column but when infact it doesnt support it your best bet is to rewrite it using UNION/UNION ALL Ahh I just realized something. There is no ID column for both tables. In one table the column is called 'customerID', in the other table is just 'ID'. Is that the reason for the error ?
|
|
|
|
|
|
TSseiferalmercy
|
Sep 18 2020, 11:32 AM
|
Getting Started

|
QUOTE(jackoats.my @ Sep 17 2020, 08:50 PM) FULL OUTER JOIN is equivalent to LEFT OUTER JOIN UNION RIGHT OUTER JOIN So you can also try the above step if the FULL OUTER JOIN doesn't work. I used right outer join and it works Thanks again. Could you suggest a website where I could get the whole list of syntax ?
|
|
|
|
|
|
bumpo
|
Sep 18 2020, 11:33 AM
|
|
QUOTE(seiferalmercy @ Sep 18 2020, 11:26 AM) Ahh I just realized something. There is no ID column for both tables. In one table the column is called 'customerID', in the other table is just 'ID'. Is that the reason for the error ? error is complaining about 'on clause' meaning your joining condition. most likely mysql is wrongly returning the error due to "full join"
|
|
|
|
|
|
jackoats.my
|
Sep 20 2020, 12:09 AM
|
Getting Started

|
Ha, you can read the MySQL manual (documentation) QUOTE(seiferalmercy @ Sep 18 2020, 11:32 AM) I used right outer join and it works Thanks again. Could you suggest a website where I could get the whole list of syntax ? This post has been edited by jackoats.my: Sep 20 2020, 12:11 AM
|
|
|
|
|