This question already has answers here:
MySQL string replace
(6 answers)
Closed 7 years ago.
I have following record in MySQL database:
id name alias
1 vijay hazare vijay_hazare
2 ravi shastri ravi_shastri
3 rahul dravid rahul_dravid
I want them like this.
id name alias
1 vijay hazare vijay.hazare
2 ravi shastri ravi.shastri
3 rahul dravid rahul.dravid
I have 6000 records in my database and I want to change _ to .(dot) in "alias" field to all table.
You can use REPLACE() function with UPDATE statement:
UPDATE yourtable SET `alias`=REPLACE(`alias`,'_','.');
Related
This question already has answers here:
Count boolean field values within a single query
(4 answers)
Closed 4 months ago.
Suppose a table have a column with values like:
column
3
1
1
3
4
1
2
I want to retrieve that how many times there is 1 in column and how many times > 1.
Is there anyway to do this within one query?
I want the data to be fetched like this:
one | greater_than_one
3 | 4
Thanks in advance.
Simple:
select sum(col1=1) as one ,
sum(col1>1) as greater_than_one
from test_tbl;
https://dbfiddle.uk/348f5YOK
This question already has answers here:
Can I concatenate multiple MySQL rows into one field?
(16 answers)
Closed 5 years ago.
When i run the query:
select * from table where UserID='21';
My sql result shows as below:
UserID FName LName StatusID Company Notes
21 Sam Jones 21 AT&T Applied
21 Sam Jones 32 Verizon In Process
21 Sam Jones 36 T-Mobile Applied
Is there a way for me to get the result in the following manner ?
UserID FName LName StatusID Company Notes
21 Sam Jones [21,32,36] [AT&T,Verizon,T-mobile] [Applied,In Process,Applied]
Any tips in the right direction would be of great help too.
Thanks.
I did it with a data table I have try this for your's
This question already has answers here:
Remove duplicate rows in MySQL
(26 answers)
Closed 6 years ago.
I got double row in my sql database and I don't know how to remove them.
(my sql table)
date quantity city supervisor bonus empnum
---------- -------- ----- ---------- ----- ------
2016-05-01 46 laval mlasselin 10 837
2016-05-01 46 laval mlasselin 10 837
2016-05-01 46 laval mlasselin 10 837
2016-05-01 43 laval mlasselin 25 880
I want to use a SQL query to delete extra row only keep one.
I have this kind of row all my database I need a sql query to remove them all and keep only one date and one empnum
I dont have id like the other standart table
Q: What SQL query can I use to remove the duplicate rows?
DELETE FROM foo WHERE a=12345 LIMIT 1;
Find something unique that identifies the lines you want to delete and then use the LIMIT clause.
This question already has answers here:
SQL select only rows with max value on a column [duplicate]
(27 answers)
Closed 7 years ago.
Alright, so I have a table of persons and each person belongs to a couple. I need to run a query that gets only the older member of each couple. Here is my schema:
id BIGINT
name VARCHAR(32)
couple_id VARCHAR(255)
birthdate TIMESTAMP
And the query I'm working on:
SELECT * FROM person
GROUP BY couple_id
HAVING birthdate > ???
The couple_id is a randomized string. Currently the output looks like this:
1 John AAA 1985/12/04
2 Jane AAA 1984/01/02
3 Christopher BBB 1991/07/07
4 Christina BBB 1992/08/20
5 Alex CCC 1995/02/07
6 Alexandra CCC 1996/11/12
I need a query that returns the rows John, Christina, and Alexandra.
One way to do it is using a derived table.
SELECT p1.*
FROM person p1
join (select couple_id, max(birthdate) as mxbrthdt
from person group by couple_id) p2
on p2.couple_id = p1.couple_id and p1.birthdate = p2.mxbrthdt
This question already has an answer here:
MySQL : Multiple row as comma separated single row
(1 answer)
Closed 9 years ago.
Here is my table information
Id Name
1 aaa
1 bbb
2 ccc
2 ddd
Ids are the repeated one. Now I want the result like
1 aaa,bbb
2 ccc,ddd
How can I do that in Mysql ?
Use GROUP_CONCAT()
select id, group_concat(name) as names
from your_table
group by id