ER_BAD_FIELD_ERROR: Unknown column 'table.column' in 'on clause' - mysql

i'm getting a really confused problem... i'm triying to do a query:
SELECT ordenes_servicio.idorden, estatus_orden.descripcion AS estatus, tipo_orden.descripcion AS tipo_orden, usuario.nombre, ordenes_servicio.nombres_cliente, ordenes_servicio.fecha_asig
FROM ordenes_servicio
INNER JOIN estatus_orden ON ordenes_servicio.idestatus_orden = estatus_orden.idestatus_orden
INNER JOIN tipo_orden ON ordenes_servicio.idtipo_orden = tipo_orden.idtipo_orden
INNER JOIN usuario ON ordenes_servicio.id = usuario.id
ORDER BY ordenes_servicio.idorden DESC
The problem is that when i try to run it, it say
ER_BAD_FIELD_ERROR: Unknown column 'ordenes_servicio.idusuario' in
'on clause'
But if you look at the query, there is no 'ordenes_servicio.idusuario', and yes there was, but i update my tables, both of them, and it is like the query is still triying to get that column.
When i execute the query in my MySQL Workbench it work, but dont when i try to run it in my application... Someone can help me? :/
Note: my "app" is actually a REST API in typescript, and i'm using express library

I got the answer... if can help a beginner like me someday. Im actually executing three querys, and there was one of then that still had "ordenes_servicio.idusuario"... that's all.. So check your querys!
Beginner error...

Related

SAL Query error: Unexpected keyword. (near INNER JOIN) Unrecognized statement type. (near INNER JOIN)

the first post on here so apologies if I haven't formatted things properly or if I'm not entirely clear, but I was wondering if someone may be able to assist with an error I'm facing currently.
To give some context, I'm trying to run an SQL query through my phpMyAdmin, in order to fix a customer error we were receiving on-site, after changing our Stripe accounts
WooCommerce support had provided me with the following link:
https://woocommerce.com/document/stripe-fixing-customer-errors/#section-3
However, when I try this in my phpMyAdmin, I get the following error:
Unexpected keyword. (near INNER JOIN) Unrecognized statement type.
(near INNER JOIN)
SQL Error
The query that they had asked me to run is seen here:
DELETE FROM `wp_usermeta`
WHERE meta_key IN ( '_stripe_customer_id', '_stripe_source_id', '_stripe_card_id' );
DELETE tokenmeta FROM `wp_woocommerce_payment_tokenmeta` tokenmeta
INNER JOIN `wp_woocommerce_payment_tokens` ON `wp_woocommerce_payment_tokens`.`token_id` = tokenmeta.`payment_token_id`
WHERE `wp_woocommerce_payment_tokens`.`gateway_id` = 'stripe';
DELETE FROM `wp_woocommerce_payment_tokens` WHERE gateway_id='stripe';
I had spoken to support, who had said that the query is absolutely fine and they could run it on their end, and my developer friends are also a little unsure about this.
Is someone able to shed some light on this and see if I'm doing something wrong? There is a good chance that there is a simple change that's needed that's gone over my head, but I'm just not too sure what it is!

mySQL pre-8.x Stack Overflow 'solution' not working?

Hello and thank you for any help you can provide.
I am running on a shared-server platform so I am restricted to using mySQL version 5.6.46 which means I do not have access to "recursive CTE" and "WITH" commands . After many hours of looking for a solution for how I can perform a recursive-type operation - and after trying many approaches that did not end up working - I found this Stack Overflow reference to an approach that seems like a reasonable method for what I am trying to accomplish (and simple enough for someone at my level of understanding). The method described can be found about 1/4 of the way down the page under the title of "Alternative 3: Repeated Self-joins."
In essence, I have copied the entire recommended mySQL query and modified it to my table structure BUT it triggers an error and does not run.
The error is "#1054 - Unknown column 'p2.id' in 'on clause'" which - according to my internet searches - is a common error with many references BUT each refers refers to a two-table structure with a 'comma' that - based on a SQL update years ago now requires parentheses to make it work. I am puzzled with this error on my end because I DO NOT have a two-table structure. I can find no other reason for this error. In fact, on the https://www.piliapp.com/ syntax checker it shows the syntax is fine. I would appreciate your eyes on this query to see what I'm missing. Here is my code:
select p4.ManagerID as parent4_id,
p3.ManagerID as parent3_id,
p2.ManagerID as parent2_id,
p1.ManagerID as parent_id,
p1.EmployeeID as employee_id,
p1.LastName
from cps_db_sm7.dEmployees p1
left join cps_db_sm7.dEmployees p2 on p2.id = p1.ManagerID
left join cps_db_sm7.dEmployees p3 on p3.id = p2.ManagerID
left join cps_db_sm7.dEmployees p4 on p4.id = p3.ManagerID
where 23578 in (p1.ManagerID,
p2.ManagerID,
p3.ManagerID,
p4.ManagerID)
ORDER BY 1,2,3,4,5;
The error is triggered by the first LEFT JOIN and is in reference to the ON p2.id. Could someone please look at this and suggest a solution? Thank you!

Unknown column in 'having clause':

I'm working on a project where I have many users, and a user has many posts. I'm trying to get the users that have a post count over a certain threshold, but the query I'm using doesn't seem to work.
User.where(id: user_ids)
.where(has_posts: true)
.joins(:posts)
.group('users.id')
.having('COUNT(posts.id) >= user.post_threshold')
However with this query I get Unknown column posts.id in 'having clause':
Any help on how to fix this would be greatly appreciated.
You don't need having for that, a simple where will serve you well:
User.
where(id: user_ids).
where(has_posts: true).
where('COUNT(posts.id) >= users.post_threshold').
joins(:posts).
group('users.id')
Edit: On some databases, you might need to include the aggregation in a select, adding this line to the chain:
.select('*, COUNT(posts.id)')
You can use the posts.* notation, at least in Postgres, don't know about mysql.
User.where(id: user_ids)
.where(has_posts: true)
.joins(:posts)
.group(:id)
.having('COUNT(posts.*) >= users.post_threshold')

Update one table from another within MySQL, via DBVIS SQL commander

I have adapted the solutions already posted on this question to my task but it is still generating the error:
Unknown column testbr.Tel in 'field list'
UPDATE `Test_file_base_record_subset` `testbr`
INNER JOIN `UKTI_16sep15` `ukti`
ON `ukti.UKTI_Short_UID`=`testbr.ShortUID`
SET `testbr.Tel` = `ukti.UKTI_Tel`
WHERE `testbr.Year`=2015
Please tell me where I am going wrong. Thanks.
UPDATE `Test_file_base_record_subset` `testbr`
INNER JOIN `UKTI_16sep15` `ukti` ON `ukti`.`UKTI_Short_UID`=`testbr`.`ShortUID`
SET `testbr`.`Tel` = `ukti`.`UKTI_Tel`
WHERE `testbr`.`Year`=2015

SQL unknown column when doing join

I have been getting an error "Unknown column 'guests_guest.id' in 'field list'" when i try to run the following:
SELECT guests_guest.id
FROM `guests_guest` full join
guests_guest_group
on guests_guest.id=guests_guest_group.guest_id
All the column& table names are correct. in fact, running just
SELECT guests_guest.id
FROM `guests_guest`
works just fine. I suspect there is a syntax issue I am missing. what am I doing wrong?
try:
SELECT gg.id
FROM `guests_guest` as gg
join guests_guest_group as ggg
on ggg.guest_id=gg.id
assuming guests_guest_group does not have an id column.
full join ?
Have you tried simply removing the full?
This not Oracle, it's MySQL, right? AFAIK, FULL JOIN is not implemented yet in MySQL.
The parser (because "full' is not a keyword it knows), evaluates your query as:
SELECT guests_guest.id
FROM guests_guest AS full <--- crucial note
JOIN guests_guest_group
ON guests_guest.id = guests_guest_group.guest_id
After that, guests_guest is not a name it knows, but it uses full as an alias for table guests_guest. That's why this error is produced.
If you really need FULL JOIN and not (INNER) JOIN, then search SO for how to implement FULL JOIN in MYSQL.
#rockerest: I guest so.
Two things I'd look at:
Spelling... I am a fast typer, but sometimes my fingers are dyslexic. Worst case, do a describe on each table and check column names against each other. Or, use the system-confessed column names and copy/paste.
Aliases... but, someone else has mentioned that.
So I guessed just one thing.