The 3rd column in some row holds semi colon: test 1; test 2; test 3
INSERT INTO `test_table` VALUES ('21', 'test data', 'test 1; test 2; test 3', '', 'Other', 'test data', 'Free ', '')
What should be the setting for delimeter options in phpmyadmin to import in this situation?
My test.csv file is saved in the comma(,) separated format
Tried with column separated with: \t
Throws error as: Invalid column count in CSV input on line 1.
Ignoring insert record error, solved my problem without any delimeter changes.
I've field in DB table which has string values as "principaux de l\'asthme : facteurs psychologiques, é-; blabla é tiques à-; blabla".
I want to replace string "é-;" with "é" and "à-;" with "à".
Can I have query for it?
Check With This:
REPLACE(Column_name,'K','SA')
Column_name : Name of your Column
'K' - The characters which you want to replace
'SA' - The Characters with which you want to replace
If you have to repeat this for multiple strings use cascaded Replace function such as
REPLACE(REPLACE(REPLACE(Column_Name, '3', 'test') , '2', 'test') , '1', 'test')
I have a huge table with 100 fields. Each row is timestamped. I want to find the latest non null value for all columns. I'm using MySql 5.6 InnoDB
e.g.
create table tester(
pub_id int,
pub_name varchar(20),
pub_city varchar(20),
country varchar(20),
no_of_branch varchar(20),
estd datetime
);
insert into tester (pub_id, pub_name, pub_city, country, estd)
values
(1, 'a', 'xyz', 'abcity' , 'a', '1970-01-01 00:00:01'),
(2, 'a', 'xyz', '' , 'a', '1971-01-01 00:00:01'),
(3, 'a', 'xyz', 'abcity1', 'b', '1972-01-01 00:00:01'),
(4, 'a', 'xyz', '' , 'a', '1973-01-01 00:00:01'),
(5, 'a', 'xyz', 'abcity2', '' , '1974-01-01 00:00:01'),
(6, 'b', 'lmn', 'abcity' , 'a', '1974-01-01 00:00:01'),
(7, 'b', 'xyz', '' , 'a', '1975-01-01 00:00:01'),
(8, 'b', 'sdf', 'abcity1', 'b', '1976-01-01 00:00:01'),
(9, 'b', '' , '' , 'a', '1977-01-01 00:00:01'),
(10, 'b', '' , 'abcity2', '' , '1978-01-01 00:00:01');
I want to query that would give me:
'a', 'xyz', 'abcity2', 'a'
'b', 'sdf', 'abcity2', 'b'
I don't want to use a query where i find empty values for each column of the table individually and then take a join as this would be a very cumbersome task given that my actual table has 100 columns.
I have searched for a solution for the past of couple of ours and found nothing. ANy help would be greatly appreciated.
Thanks
This might be the "tricky" way you are looking for.
First create a twin table (tester2) to receive the aggregated data. This new table must have a primary key on pub_name and all the columns you want to aggregate. Then do an INSERT INTO ON DUPLICATE KEY UPDATE. This query will basically rebuild the tester table but without duplicate and with aggregated data. In fact something like this :
insert into tester2 (pub_name, pub_city, country, no_of_branch)
select pub_name, pub_city, country, no_of_branch FROM tester order by estd desc
on duplicate key
update
pub_city = coalesce(tester2.pub_city,tester.pub_city),
country = coalesce(tester2.country,tester.country),
no_of_branch = coalesce(tester2.no_of_branch,tester.no_of_branch)
The content of tester2 will be :
PUB_NAME PUB_CITY COUNTRY NO_OF_BRANCH
a xyz abcity2 a
b sdf abcity2 a
Have a look the DB Fiddle.
Note : I assume you mean real NULL values and not empty string like the sample you provided.
I am inserting value which contains & character, but the value breaks after & while it's inserted in database. Can anyone please help me to insert value with & character?
My filed's datatype is varchar(50) and collation is utf8_general_ci.
I have used code:
NSString *strUr=[NSString stringWithFormat:#"%s%s?event_name=%#&id=%#",ServerPath,URLAddEvent,eventName,ID];
strUr = [strUr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSLog(#"url : %#",strUr);
request=[NSMutableURLRequest requestWithURL:[NSURL URLWithString:strUr]];
con=[[NSURLConnection alloc]initWithRequest:request delegate:self];
if(con)
{
webdata=[NSMutableData data];
}
in my ios code.
Any needful help will be appreciated.
You can escape any special characters.
you need to identify them using string manipulation and then create the sql accordingly.
See My fiddle.
Inserting into table:
INSERT INTO Table1
(`id`, `col1`)
VALUES
(1, 'test\&'),
(2, 'special character \''),
(3, 'speacial character \"'),
(4, 'test'),
(5, 'testing'),
(6, 'test')
;
Selection from table:
select * from Table1 where col1 like '%&%' or col1 like '%\'%'
I am trying to insert a record in mysql database using the following query, but getting the #1064-sql syntax error.
INSERT INTO RESOURCES(ID, NAME, RESTYPE, CONTENT) VALUES('4', 'Printer.TicketTotal', 0, LOAD_FILE('/home/anand/Openbravo-POS/main/src-pos/com/openbravo/pos/templates/Printer.TicketTotal.xml));
INSERT INTO RESOURCES(ID, NAME, RESTYPE, CONTENT) VALUES('4', 'Printer.TicketTotal', 0, $FILE{/home/anand/Openbravo-POS/main/src-pos/com/openbravo/pos/templates/Printer.TicketTotal.xml});
You miss ' at the end of file name -
INSERT INTO RESOURCES(ID, NAME, RESTYPE, CONTENT) VALUES
('4',
'Printer.TicketTotal',
0,
LOAD_FILE('/home/anand/Openbravo-POS/main/src-pos/com/openbravo/pos/templates/Printer.TicketTotal.xml'));