I'm doing some changes on a WordPress database. I need to replace the URLs in the GUID field on the wp-posts table with the URLs coming from another table called ebdurls. The description of the tables is as follows:
wp_posts: the field type for the two fields I need are:
ID -> bigint(20) unsigned
guid -> varchar(255)
And the table where I have the data I need to export to wp_posts is this:
ebdurls:
title -> varchar(255)
url -> varchar(255)
ebdid -> bigint(20) unsigned
Everything seems correct, but when I apply the next query it gives me an error that I really can't get. I've tried quoting fields, tables, etc... everywhere, but no luck.
mysql> update wp_posts set wp_posts.guid=ebdurls.url where wp_posts.id=ebdurls.ebdid;
ERROR 1054 (42S22): Unknown column 'ebdurls.ebdid' in 'where clause'
Where is the mistake?
You haven't specified what ebdurls is, add a from statement to your query:
UPDATE
wp_posts, ebdurls
SET
wp_posts.guid = ebdurls.url
WHERE
wp_posts.id=ebdurls.ebdid;
edit:
Bill was right, have fixed the format now. Oops.
ebdurls.* has no value. That is what is causing your error. The database has no idea what you are trying to do.
You probably need to use a subquery or add this logic into your application.
Or something like:
UPDATE wp_posts, ebdurls ...
Related
Need to find in table records both e.g. Cristy's Auction and Cristys Auction using fulltext search. I thought better do it - replace apostrophe in search query, also replace it in search data
SELECT REPLACE(other_column,'\'','') AS column FROM table
WHERE MATCH(column) AGAINST(CONVERT('+Cristys +Auction' USING latin1) COLLATE latin1_german2_ci IN BOOLEAN MODE)
throws error Error Code: 1054. Unknown column 'column' in 'where clause', as expected.
Using REPLACE(other_column,''','') directly in MATCH, or HAVING instead WHERE throws errors too...
How can I solve my problem?
Upd. DB Fiddle
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 want to write a SQL script that alters a column's attribute to null from the not-null state.
Tried:
SELECT COLUMNPROPERTY('prefetching_rules', 'date_delete','AllowsNull') AS 'AllowsNull';
But getting following error:
Error Code: 1054. Unknown column 'COLUMNPROPERTY' in 'field list'
For this you should use alter table (assuming you column is a varchar of 255) just apply modify.
Columns are nullable by default and so just not assign other constrains as NOT NULL
ALTER TABLE mytable MODIFY your_column_name VARCHAR(255);
This query will give you detailed info about all 'not nullable' columns
in all tables in 'your_database_name_here'.
SELECT *
FROM information_schema.columns
WHERE TABLE_SCHEMA = 'your_database_name_here'
AND IS_NULLABLE = 'NO';
Then you have to decide which of them you want to modify.
Just FYI u can't use this query as sub query in ALTER sql because it doesn't accept subqueries
I have a table ABC that has many columns, two of which are:
ID - VARCHAR(10) and ROLE VARCHAR(10).
Now I have been trying to update the column ROLE using the ID and this is the query:
UPDATE TABLE ABC
SET ROLE='READ_ONLY'
WHERE ID='AB234PQR'
Now for some unknown reason, i have been getting the error - truncated incorrect integer value. I have no idea where I am going wrong.I have been banging my head over this for a while now.
I have visited other questions with the similar title.All use convert or some other function in where clause, But I have not used any such thing, still it gives me the same error.
I checked the table description and it seems fine. Where can I be going wrong? Any help is appreciated.
Can you please try this:
UPDATE ABC
SET ROLE='READ_ONLY'
WHERE ID='AB234PQR'
The correct syntax to update table entries is:
UPDATE `table_name`
SET `column_name` = 'value'
WHERE `column_name2` = 'value2';
It is as well recommended to use backticks around table names and column names, just like the way you can see in my snippet above.
Therefore using
UPDATE `ABC`
SET `ROLE` = 'READ_ONLY'
WHERE `ID` = 'AB234PQR'
should do the trick.
After table setup, I suddenly remember to update it by adding one column and assign all the same value to that column. So I wrote the queries on Workbench like this
ALTER TABLE sthebc3_cle ADD COLUMN Species char(30) AFTER Genome_ACC;
SET SQL_SAFE_UPDATES=0;
UPDATE cle.sthebc3_cle
SET Species='StHe';
But it reported error like
error 1054: unknown column "Species" in "field list
I checked table after ALTER, The new column "Species" was indeed added to the column and values are NULL.
How could be the error reported?
You need to make sure that the current session is the database you want. There is always a selected database in MySQL.
If you want to be 100% sure which database you are using you Always put nameofthedatabase.tablename,
For the table
ALTER TABLE cle.sthebc3_cle ADD COLUMN Species char(30) AFTER Genome_ACC;
SET SQL_SAFE_UPDATES=0;
UPDATE cle.sthebc3_cle
SET Species='StHe';
For you view, try this
USE cle;
CREATE VIEW all_cle AS
(SELECT Species, Genome_ACC, CLE_start, CLE_end, CLE_domain
FROM nameofdatabase.cowpea_cle)
UNION
(SELECT Species, Genome_ACC, CLE_start, CLE_end, CLE_domain
FROM nameofdatabase.sthebc3_cle);