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
Related
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
Below is the query I used to select multiple columns from one of my tables.
I get the column names from user to select from the table.
If the user gives a wrong column name it shows Unknown column error. How can I check if that column exists in the table before going to select?
SELECT `address_id`,`address_firstname`,` afserfw`
FROM `patsm_addresstable`
WHERE `address_id`='28'
LIMIT 0, 25
This would give the following error:
#1054 - Unknown column ' afserfw' in 'field list'
This query will give you a list of columns in a particular table with their datatypes.
SELECT COLUMN_NAME, DATA_TYPE
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_SCHEMA = DATABASE()
AND TABLE_NAME = 'tablename'
You can, when constructing a query against any table, use this resultset to determine whether a given column exists.
But be careful: a web application allowing end-users to give you column names is hard to make secure against intrusion by cybercrooks.
Why does this query produce an "Duplicate entry" error?
TRUNCATE parim_firm_tag_names;
INSERT INTO parim_firm_tag_names (firm_tag_name_value)
SELECT DISTINCT sona
FROM parim_marksona;
Error message:
SQL Error (1062): Duplicate entry '1-??????? ??????' for key
'firm_tag_name_value'
As you can see, firm_tag_name_value has an unique index, I use DISTINCT select and I'm truncating all existing data from tag_names.
What could produce this error?
This could be happening because of different collations defined on both tables parim_firm_tag_names and parim_marksona as string comparisons using distinct may results in different values on case sensitive and case insensitive collation values.
You can check collation of columns using this query:
SHOW FULL COLUMNS FROM parim_marksona;
SHOW FULL COLUMNS FROM parim_firm_tag_names;
To avoid this error, you can convert collation of column sona to the collation of column firm_tag_name_value using COLLATE, while selecting the distinct values from table parim_marksona.
Assuming collation of column firm_tag_name_value as latin1_swedish_cs:
TRUNCATE parim_firm_tag_names;
INSERT INTO parim_firm_tag_names (firm_tag_name_value)
SELECT DISTINCT sona COLLATE latin1_swedish_cs
FROM parim_marksona;
This should work without errors.
For more details refer manual Column Character Set and Collation.
Different character sets between the two tables, perhaps?
I have created a MYSQL stored procedure that searches all columns of a table (parameter 1) to find if any of them contains a string (parameter 2). The problem is that when I compare a datetime column with a string that contains greek characters I get the following error:
SELECT * FROM my_table WHERE my_datetime LIKE '%ΕΛΛΗΝΙΚΑ%';
Illegal mix of collations for operation 'like'
The execution of the query is successful when I use latin characters. I know how to avoid checking columns based on their datatype, however I really want to be able to search for datetime strings as well. I use MySQL 5.5.24. The collation of the database is utf8_general_ci and the collation of the server is latin1_swedish_ci. I have tried the command SET NAMES utf8 before the query, with no luck though. Any ideas? Thanks.
I had a problem with similar query:
SELECT * FROM some_table WHERE some_date LIKE '%2012-01%';
The result was an "Illegal mix of collations" error.
Using simply DATE_FORMAT function helped:
SELECT * FROM some_table WHERE DATE_FORMAT(some_date, '%Y-%m-%d') LIKE '%2012-01%';
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 ...