mysql-error-1054

Error Code: 1054. Unknown column

点点圈 提交于 2019-12-23 18:28:46
问题 I have the following SQL statement: SELECT efforts.user_id, project_tasks.task_name, sum(hours) FROM efforts, users, project_tasks INNER JOIN PROJECT_TASKS pu ON efforts.project_task_id = pu.id INNER JOIN USERS u ON efforts.users_id = u.id WHERE project_tasks.project_id = '2'; And when I run it I get the following error: Error Code: 1054. Unknown column 'efforts.project_task_id' in 'on clause' Why am I getting this error? Project_task_id belongs to efforts table Image of my efforts table

MySQL Trigger - update table with value selected from another table

别来无恙 提交于 2019-12-23 04:07:30
问题 I'm having problems updating row in a table with value selected from another table in MySQL Trigger. My Trigger looks like this CREATE TRIGGER update_user_last_login AFTER INSERT or UPDATE ON last FOR EACH ROW BEGIN DECLARE _user_id INTEGER; SELECT user_id INTO _user_id FROM user_profile WHERE user_name = NEW.username; UPDATE user set last_login = NEW.seconds WHERE id = _user_id; END I'm getting error message: ERROR 1054 (42S22): Unknown column '_user_id' in 'where clause' Could somebody

How to use a temp column in the where clause

倾然丶 夕夏残阳落幕 提交于 2019-12-21 04:23:14
问题 Why can't I use a temporary column in the where clause? For example, this query: Select product_brand, (CASE WHEN COUNT(product_brand)>50 THEN 1 ELSE 0 END) AS brand_count FROM products WHERE 1 GROUP BY product_brand This brings up two columns, one called product_brand and one called brand_count . brand_count is created on the fly and is always 1 or 0 depending on whether or not there are 50 or products with that brand. All this makes sense to me, except that I can't select only if brand

MySQL #1054 unknown column

只愿长相守 提交于 2019-12-20 03:32:31
问题 When running the query below, I end up with a MYSQL error in PHPMyAdmin: #1054 - Unknown column 'wd.Datum' in 'having clause' This query belongs in a time reporting application, where users report time worked on projects on a daily basis. There's a table for days that are expected working days, a table of all employees and a table with information about the current work rate. The last table is also used to determine when a user was employed. The idea is to get all working days and all users

Filtering on an alias in mysql

断了今生、忘了曾经 提交于 2019-12-19 04:41:31
问题 Why doesn't the following query work? Mysql complains about z - can't I use an alias in the WHERE clause? SELECT x + y AS z, t.* FROM t WHERE x = 1 and z = 2 The error that I get is: Error Code : 1054 Unknown column 'z' in 'where clause' 回答1: http://dev.mysql.com/doc/refman/5.0/en/problems-with-alias.html Standard SQL disallows references to column aliases in a WHERE clause. This restriction is imposed because when the WHERE clause is evaluated, the column value may not yet have been

trying to get the number of months

这一生的挚爱 提交于 2019-12-18 07:12:14
问题 membership table membership_startdate (2011-01-12) membership_dueday values like only dates (09,08,07) member_id member table member_id How can I get count of the number of months that the member has paid till now and taking into consideration (membership_dueday)? Suppose if membership_startdate is 2011-01-01 and membership_dueday is 15, the the number of months count up to till now is 5.5 I have tried this code SELECT COUNT(NUMBEROFMONTHS) FROM membership WHERE NUMBEROFMONTHS = PERIOD_DIFF

Unknown Column in Where Clause

余生长醉 提交于 2019-12-14 02:23:12
问题 Why MySQL claims of not finding a column? I did specify it in 'select clause'. MySQL 5.1.39 Error Code: 1054 Unknown column ' dt' in 'where clause' Query: -- Generate a Table for Every Day in 2008 Year SELECT DATE_ADD('2008-01-01', INTERVAL (ones.num + tens.num + hundreds.num) DAY) dt FROM (SELECT 0 num UNION ALL SELECT 1 num UNION ALL SELECT 2 num UNION ALL SELECT 3 num UNION ALL SELECT 4 num UNION ALL SELECT 5 num UNION ALL SELECT 6 num UNION ALL SELECT 7 num UNION ALL SELECT 8 num UNION

MySQL LEFT JOIN after 5.0.12 changes - How to rewrite query

帅比萌擦擦* 提交于 2019-12-13 04:07:08
问题 After 5.0.12 MySQL changed the syntax for left joins to match SQL2003 standard. So ... FROM t1 , t2 LEFT JOIN t3 ON (expr) needs to be rewritten as ... FROM (t1 , t2) LEFT JOIN t3 ON (expr or else it will be parsed as ... FROM t1 , (t2 LEFT JOIN t3 ON (expr)) Now, I have an ancient app I'm porting from MySQL 3.23 (eek!) to 5.1, and the old code has this query: select b.*, c.*, g.*, p.perfname, p.persname from bookings b, customer c left join grade g on b.chrggrade=g.grcode left join person p

How to refer 'decider' in the where clause from the following mysql query?

陌路散爱 提交于 2019-12-11 10:58:58
问题 How to refer 'decider' in the where clause from the following mysql query? SELECT *, CASE WHEN (cond1) THEN 1 WHEN (cond2) THEN 2 END as decider FROM t1, t2 WHERE cond12 AND decider <> NULL I tried it, and I got a 1054: Unknown column in where clause error. 回答1: Use: SELECT *, CASE WHEN (cond1) THEN 1 WHEN (cond2) THEN 2 ELSE NULL END as decider FROM t1, t2 WHERE cond12 HAVING decider IS NOT NULL The earliest MySQL allows you to use column aliases is the GROUP BY clause You need to use IS

Getting ERROR 1054 (42S22) while i am executing the MySQL command in the Terminal

青春壹個敷衍的年華 提交于 2019-12-11 08:46:40
问题 I want to collect the data from the crawlstatus table where status='RECEIVED' and I want to store that data in an file. When I am trying to do this in the terminal I am getting ERROR 1054 (42S22) . Here is the command that which i used to get the data: sudo sh -c '/usr/local/mysql/bin/mysql -h localhost -P 3306 --user=root --password=XXXXXXXXXX -e "select count(*) from crawlstatus where status='RECEIVED';" test_navin > size.log' I am getting the following ERROR: ERROR 1054 (42S22) at line 1: