MYSQL : get unique substrings from string [closed] - mysql

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
example field in mysql table with only one row:
james is a good boy james he is good and is active
SELECT FUNCTION(field)
FROM table
should return only the unique words in the field:
james is a good boy he and active
I know how to do this using PHP.
I wish to do this using MYSQL.
Please help.
Thank you.

MySQL has little support for regular expressions, so you the resulting solution could be a little complicated:
SELECT
GROUP_CONCAT(word ORDER BY min_n SEPARATOR ' ')
FROM (
SELECT
id,
MIN(numbers.n) min_n,
SUBSTRING_INDEX(SUBSTRING_INDEX(tableName.st, ' ', numbers.n), ' ', -1) word
FROM
numbers INNER JOIN tableName
ON LENGTH(st)>=LENGTH(REPLACE(st, ' ', ''))+numbers.n-1
GROUP BY
id, word
) s
GROUP BY
id
(You need to have a numbers table). Please see fiddle here.

Related

Mysql function trim doesn't work [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I tried trim function many times to remove white spaces on a table column but it didn't .
update table_name set column_name= TRIM(column_name)
any guide please.
Why don't you just do SELECT REPLACE(column_name, ' ', '') FROM table_name?
If you want to remove the white spaces from both left and right side, trim() should do the work for you.
You can check the length of the returned values as follows:
select trim(column_name), char_length(trim(column_name)) as length from table_name
See this SQLFiddle demo
This is working fine for me.
Try this,
update yourtablename set price = REPLACE( price, ' ', '');

Is there any sql-query to check the value is exist or not in db table [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
In my database table have this value,i have to check this email value 'abc#gmail.com' is exist in the database or not.
abc#gmail.com
edf#dfg.com
xyz#abcinfo.com
12345#fdfg.com
If 'abc#gmail.com' value is exist in the database table, output is true else false, so how to write the query for this to achieve?
thanks
Kumar
You can do something as simple as
select CASE WHEN count(1) > 0 THEN 'true' ELSE 'false' END from table where email = 'abc#gmail.com'
But you should give some more information for a beater answer.
you can write query like
SELECT IF(COUNT(*) >0, TRUE,FALSE)as response FROM <tablename> WHERE emailid='edf#dfg.com';
select exists(
SELECT 1 FROM <tableName> WHERE email LIKE 'abc#gmail.com'
)

Replace character between numbers [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I converted phpbb2 forum to phpbb3.
But I have problem with phpbb2 posts links which remained in MySQL database.
phpbb2 posts links are eg.
/viewtopic.php?p=106352#106352
and phpbb3 are:
/viewtopic.php?p=106352#p106352
(there is letter p after #)
Current links from phpbb2 are not working, after convert,
so I need help replacing # between posts id (numbers) in MySQL DB.
I got a lot of links like:
/viewtopic.php?p=106352#106352
and I need to replace # with p ( add p at the end)
like:
/viewtopic.php?p=106352#p106352
I don't know much MySQL, so I stuck.
Please help
One possible approach:
UPDATE phpbb_posts
SET post_text = REPLACE(post_text, '#', '#p')
WHERE post_text REGEXP '^[^#]*p=[0-9]+#[0-9]+$'
WHERE clause is specified to prevent updating links that do not follow the format.
SQL Fiddle.
select replace('/viewtopic.php?p=106352#106352','#','#p')
update myTable
set myColumn = replace(myColumn, '#', '#p')
where someColumn = someThing

How to select not-wellformed data [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have a huge table I'm trying to port to a new database, there's a row that stores number of doors, body style, and gearbox like "4SDa" for 4 door sedan, auto or "5HBm" for 5 door hatchback, manual.
I need to select all rows that AREN'T like this so I can edit them as they are causing issues.
How can I select any row that isn't in the format
number-letter-letter-letter' (case insensitive)
select * from your_table
where your_column not regexp '^[0-9][a-zA-Z]{3,3}$'
Regex Tester
SELECT '4SDa' REGEXP '^[0-9][a-z]{3}$'; --> 1
SELECT '4SDaa' REGEXP '^[0-9][a-z]{3}$'; --> 0
SELECT 'AAbb' REGEXP '^[0-9][a-z]{3}$'; --> 0

How to fetch mysql data having brackets? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I want to fetch mysql data having round brackets e.g. ABCD(XYZ). When I run query
"SELECT * FROM tablename WHERE Column = 'ABCD(XYZ)'"
it returns an empty result. Please suggest a way. Thanks in advance!
this should work:
INSERT INTO `tablename` (`Column`) VALUES ('ABCD(XYZ)');
SELECT * FROM `tablename` WHERE `Column` = 'ABCD(XYZ)'";
Maybe 'ABCD(XYZ)' is not exactly the value of your data (for example if you inserted some whitespaces before or after it.)
You can try it with a like to find that out:
SELECT * FROM `tablename` WHERE `Column` LIKE '%ABCD(XYZ)%'";
Another possibility is that your value has been converted with htmlentities and you saved something like this:
'ABCD&40;XYZ&41;'
&40; Left parenthesis
&41; Right parenthesis