I have created a view which contains field 'Spieltag'. Here you can see my view...
CREATE
ALGORITHM = UNDEFINED
DEFINER = `root`#`localhost`
SQL SECURITY DEFINER
VIEW `auswärtsergebnisse` AS
SELECT
`bundesligaergebnisse`.`Spieltag` AS `Spieltag`,
`bundesligaergebnisse`.`Heimteam` AS `Heimteam`,
`bundesligaergebnisse`.`Heimtore` AS `Heimtore`
FROM
`bundesligaergebnisse`
But when I run SELECT Spieltag FROM analytics.auswärtsergebnisse;
I get Error Code 1054, Unknown field 'Spieltag' in 'field list'. With Heimteam and Heimtore is everything fine and select * works fine.
Related
How does one display the temporary column name (which is not present in the table) ONLY, when using the case statement?
For example:
select my_column_name,
case
when X <=10 then 'A'
when X >=11 AND X <=19 then 'B'
when X >=20 then 'C'
else 'Some error occured'
END AS my_column_name
from table_name
now if I execute this MySql workbench gives this error:
Error Code: 1054. Unknown column 'my_column_name' in 'field list'
this will work if I give column names which are in the table or just give the * but it does not work if I just want the temporary name/alias (I'm not sure what this column is called)
I am working on a mysql procedure that I can run on all of my client environments however I am running into one issue. Some of my clients have a particular column on the database and others do not.
I am trying to use update ignore but I still get an error if the column doesnt exist.
I know I can query information schema for a count where that column exists, but I'm wondering if there is a more simplistic way to achieve this.
update ignore table1 set columnA = null;
ERROR 1054 (42S22): Unknown column 'columnA' in 'field list'
You have two options:
First solution: Check first if the column exists.
SELECT t.table_name, (c.column_name IS NULL) AS columnA_present
FROM INFORMATION_SCHEMA.TABLES AS t
LEFT OUTER JOIN INFORMATION_SCHEMA.COLUMNS AS c
ON t.table_name = c.table_name and c.column_name = 'columnA'
WHERE t.table_name = 'table1';
Second solution: Run the UPDATE and catch the error. Check if the error is 1054. If so, then skip it. If not, then it's some other error so report it.
I'm trying to run the following code in a procedure. It is the very first line of code in the procedure after the BEGIN
update `deleteRequestsInitial`
SET `mamaID` = (SELECT `id` FROM `love_users`
WHERE `love_users`.`email` = `deleteRequestsInitial`.`Email`);
When I run it in the phpmyadmin SQL environment, it works fine. But when I call the procedure, I get the error:
Unknown column 'deleteRequestsInitial.Email' in 'where clause'
I've looked through a lot of the posts on the 'Unknown column' error, but none of the suggested workarounds seem to be working for me.
You are probably really running this:
update `deleteRequestsInitial`
SET `mamaID` = (SELECT `id` FROM `love_users`
WHERE `love_users`.`email` = `deleteRequestsInitial.Email`);
Or possibly, the column is email, not Email.
I would suggest just dropping all the back ticks:
UPDATE deleteRequestsInitial dri
SET mamaID = (SELECT id
FROM love_users lu
WHERE lu.email = dri.Email
);
I need to fetch a value from a table with three possibilities: 1) The field exists and it's not null, so it returns the value of the field 2) the field exists but it's null, so it returns is-null-string 3) The field doesn't exists, so it returns not-existing-string
I am trying to run this query but I get this error message #1054 - Unknown column 'm.my_field' in 'field list'
SELECT if (exists(SELECT *
FROM information_schema.COLUMNS
WHERE TABLE_NAME = 'my_table' AND COLUMN_NAME = 'my_field'
), IFNULL(m.my_field, 'is-null-string'), 'not-existing-string'
) AS my_field,
m.*
FROM my_table m
Any idea how can I get it done in mysql 5.6?
What you are looking for is DESCRIBE:
DESCRIBE my_table;
Look at the result to see if your field exists. Note, you don't want this code to be in your application. You need to know your table fields to run queries. You might only use this to generate some boilerplate code.
I have a database called test containing a table called Categories. I want to find the primary key column name in this table.
I wrote this SQL query:
Select COLUMN_NAME
From INFORMATION_SCHEMA.KEY_COLUMN_USAGE
Where OBJECTPROPERTY(OBJECT_ID(CONSTRAINT_SCHEMA+'.'+CONSTRAINT_NAME),
'IsPrimaryKey') = 1 AND TABLE_NAME = 'Categories'
SQL Error:
Error: ERROR 1305 (42000): FUNCTION test.OBJECTPROPERTY does not exist
How can I solve this problem?
That's why you are getting the error. OBJECTPROPERTY is a SQL Server built-in function and not present in MySQL. Moreover, your posted query will never compile cause that's a SQL Server specific query.