MySQL select from text column with filtering
up vote
2
down vote
favorite
I would like to query a database which is MySQL 5.
Let's say database name is db
and the table name is table
and the column name is column
and that column is a text
containing the following for example:
aksksksksjsjk&ct=100&rxp=0918&rpa=100
aksksksksjsjk&ct=100&rxp=1018&ls=1
So i would like to query that table and grep only where rxp >
0918
so I'm expecting the result to be:
aksksksksjsjk&ct=100&rxp=1018&ls=1
I tried with SELECT column FROM db.table WHERE column LIKE '%rxp=1018%'
and it's working ! but that's meant that i will need to manually insert all dates !
mysql sql regex
New contributor
add a comment |
up vote
2
down vote
favorite
I would like to query a database which is MySQL 5.
Let's say database name is db
and the table name is table
and the column name is column
and that column is a text
containing the following for example:
aksksksksjsjk&ct=100&rxp=0918&rpa=100
aksksksksjsjk&ct=100&rxp=1018&ls=1
So i would like to query that table and grep only where rxp >
0918
so I'm expecting the result to be:
aksksksksjsjk&ct=100&rxp=1018&ls=1
I tried with SELECT column FROM db.table WHERE column LIKE '%rxp=1018%'
and it's working ! but that's meant that i will need to manually insert all dates !
mysql sql regex
New contributor
add a comment |
up vote
2
down vote
favorite
up vote
2
down vote
favorite
I would like to query a database which is MySQL 5.
Let's say database name is db
and the table name is table
and the column name is column
and that column is a text
containing the following for example:
aksksksksjsjk&ct=100&rxp=0918&rpa=100
aksksksksjsjk&ct=100&rxp=1018&ls=1
So i would like to query that table and grep only where rxp >
0918
so I'm expecting the result to be:
aksksksksjsjk&ct=100&rxp=1018&ls=1
I tried with SELECT column FROM db.table WHERE column LIKE '%rxp=1018%'
and it's working ! but that's meant that i will need to manually insert all dates !
mysql sql regex
New contributor
I would like to query a database which is MySQL 5.
Let's say database name is db
and the table name is table
and the column name is column
and that column is a text
containing the following for example:
aksksksksjsjk&ct=100&rxp=0918&rpa=100
aksksksksjsjk&ct=100&rxp=1018&ls=1
So i would like to query that table and grep only where rxp >
0918
so I'm expecting the result to be:
aksksksksjsjk&ct=100&rxp=1018&ls=1
I tried with SELECT column FROM db.table WHERE column LIKE '%rxp=1018%'
and it's working ! but that's meant that i will need to manually insert all dates !
mysql sql regex
mysql sql regex
New contributor
New contributor
New contributor
asked Nov 8 at 9:54
Ike White
111
111
New contributor
New contributor
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
up vote
2
down vote
Assuming that the value that comes after rxp=
is always of length 4 in the format MMYY
then the following should do the trick for you. Note that since your date is in string format, we need to perform check for both the month and year separately.
SELECT *
FROM db.table
WHERE LEFT(SUBSTRING_INDEX(testColumn, 'rxp=', -1), 2) > '09'
AND MID(SUBSTRING_INDEX(testColumn, 'rxp=', -1), 3, 2) >= '18'
Assuming you've got the following values under column
:
aksksksksjsjk&ct=100&rxp=0918&rpa=100
aksksksksjsjk&ct=100&rxp=1018&ls=1
aksksksksjsjk&ct=100&rxp=1116&ls=1
The output of the query should be
aksksksksjsjk&ct=100&rxp=1018&ls=1
However, I would highly recommend you to normalise your table and store every value in a separate column (ct
, rxp
, rpa
, ls
etc.) instead of having a lot of information combined into a single string.
you mentionedFROM db.table A
so what isA
refer to ?
– Ike White
Nov 8 at 10:17
@IkeWhite My bad. See my updated answer.
– Giorgos Myrianthous
Nov 8 at 10:18
add a comment |
up vote
0
down vote
create table #temp(
Integ Integer
)
insert into #temp values(CONVERT(INT, right(left('aksksksksjsjk&ct=100&rxp=0918&rpa=100', 29),4)) ) ,
(CONVERT(INT, right(left('aksksksksjsjk&ct=100&rxp=1018&ls=1', 29),4)) )
select * from #temp
where Integ >918
drop table #temp
hope it helps you
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
Assuming that the value that comes after rxp=
is always of length 4 in the format MMYY
then the following should do the trick for you. Note that since your date is in string format, we need to perform check for both the month and year separately.
SELECT *
FROM db.table
WHERE LEFT(SUBSTRING_INDEX(testColumn, 'rxp=', -1), 2) > '09'
AND MID(SUBSTRING_INDEX(testColumn, 'rxp=', -1), 3, 2) >= '18'
Assuming you've got the following values under column
:
aksksksksjsjk&ct=100&rxp=0918&rpa=100
aksksksksjsjk&ct=100&rxp=1018&ls=1
aksksksksjsjk&ct=100&rxp=1116&ls=1
The output of the query should be
aksksksksjsjk&ct=100&rxp=1018&ls=1
However, I would highly recommend you to normalise your table and store every value in a separate column (ct
, rxp
, rpa
, ls
etc.) instead of having a lot of information combined into a single string.
you mentionedFROM db.table A
so what isA
refer to ?
– Ike White
Nov 8 at 10:17
@IkeWhite My bad. See my updated answer.
– Giorgos Myrianthous
Nov 8 at 10:18
add a comment |
up vote
2
down vote
Assuming that the value that comes after rxp=
is always of length 4 in the format MMYY
then the following should do the trick for you. Note that since your date is in string format, we need to perform check for both the month and year separately.
SELECT *
FROM db.table
WHERE LEFT(SUBSTRING_INDEX(testColumn, 'rxp=', -1), 2) > '09'
AND MID(SUBSTRING_INDEX(testColumn, 'rxp=', -1), 3, 2) >= '18'
Assuming you've got the following values under column
:
aksksksksjsjk&ct=100&rxp=0918&rpa=100
aksksksksjsjk&ct=100&rxp=1018&ls=1
aksksksksjsjk&ct=100&rxp=1116&ls=1
The output of the query should be
aksksksksjsjk&ct=100&rxp=1018&ls=1
However, I would highly recommend you to normalise your table and store every value in a separate column (ct
, rxp
, rpa
, ls
etc.) instead of having a lot of information combined into a single string.
you mentionedFROM db.table A
so what isA
refer to ?
– Ike White
Nov 8 at 10:17
@IkeWhite My bad. See my updated answer.
– Giorgos Myrianthous
Nov 8 at 10:18
add a comment |
up vote
2
down vote
up vote
2
down vote
Assuming that the value that comes after rxp=
is always of length 4 in the format MMYY
then the following should do the trick for you. Note that since your date is in string format, we need to perform check for both the month and year separately.
SELECT *
FROM db.table
WHERE LEFT(SUBSTRING_INDEX(testColumn, 'rxp=', -1), 2) > '09'
AND MID(SUBSTRING_INDEX(testColumn, 'rxp=', -1), 3, 2) >= '18'
Assuming you've got the following values under column
:
aksksksksjsjk&ct=100&rxp=0918&rpa=100
aksksksksjsjk&ct=100&rxp=1018&ls=1
aksksksksjsjk&ct=100&rxp=1116&ls=1
The output of the query should be
aksksksksjsjk&ct=100&rxp=1018&ls=1
However, I would highly recommend you to normalise your table and store every value in a separate column (ct
, rxp
, rpa
, ls
etc.) instead of having a lot of information combined into a single string.
Assuming that the value that comes after rxp=
is always of length 4 in the format MMYY
then the following should do the trick for you. Note that since your date is in string format, we need to perform check for both the month and year separately.
SELECT *
FROM db.table
WHERE LEFT(SUBSTRING_INDEX(testColumn, 'rxp=', -1), 2) > '09'
AND MID(SUBSTRING_INDEX(testColumn, 'rxp=', -1), 3, 2) >= '18'
Assuming you've got the following values under column
:
aksksksksjsjk&ct=100&rxp=0918&rpa=100
aksksksksjsjk&ct=100&rxp=1018&ls=1
aksksksksjsjk&ct=100&rxp=1116&ls=1
The output of the query should be
aksksksksjsjk&ct=100&rxp=1018&ls=1
However, I would highly recommend you to normalise your table and store every value in a separate column (ct
, rxp
, rpa
, ls
etc.) instead of having a lot of information combined into a single string.
edited Nov 8 at 10:26
answered Nov 8 at 10:14
Giorgos Myrianthous
3,52621233
3,52621233
you mentionedFROM db.table A
so what isA
refer to ?
– Ike White
Nov 8 at 10:17
@IkeWhite My bad. See my updated answer.
– Giorgos Myrianthous
Nov 8 at 10:18
add a comment |
you mentionedFROM db.table A
so what isA
refer to ?
– Ike White
Nov 8 at 10:17
@IkeWhite My bad. See my updated answer.
– Giorgos Myrianthous
Nov 8 at 10:18
you mentioned
FROM db.table A
so what is A
refer to ?– Ike White
Nov 8 at 10:17
you mentioned
FROM db.table A
so what is A
refer to ?– Ike White
Nov 8 at 10:17
@IkeWhite My bad. See my updated answer.
– Giorgos Myrianthous
Nov 8 at 10:18
@IkeWhite My bad. See my updated answer.
– Giorgos Myrianthous
Nov 8 at 10:18
add a comment |
up vote
0
down vote
create table #temp(
Integ Integer
)
insert into #temp values(CONVERT(INT, right(left('aksksksksjsjk&ct=100&rxp=0918&rpa=100', 29),4)) ) ,
(CONVERT(INT, right(left('aksksksksjsjk&ct=100&rxp=1018&ls=1', 29),4)) )
select * from #temp
where Integ >918
drop table #temp
hope it helps you
add a comment |
up vote
0
down vote
create table #temp(
Integ Integer
)
insert into #temp values(CONVERT(INT, right(left('aksksksksjsjk&ct=100&rxp=0918&rpa=100', 29),4)) ) ,
(CONVERT(INT, right(left('aksksksksjsjk&ct=100&rxp=1018&ls=1', 29),4)) )
select * from #temp
where Integ >918
drop table #temp
hope it helps you
add a comment |
up vote
0
down vote
up vote
0
down vote
create table #temp(
Integ Integer
)
insert into #temp values(CONVERT(INT, right(left('aksksksksjsjk&ct=100&rxp=0918&rpa=100', 29),4)) ) ,
(CONVERT(INT, right(left('aksksksksjsjk&ct=100&rxp=1018&ls=1', 29),4)) )
select * from #temp
where Integ >918
drop table #temp
hope it helps you
create table #temp(
Integ Integer
)
insert into #temp values(CONVERT(INT, right(left('aksksksksjsjk&ct=100&rxp=0918&rpa=100', 29),4)) ) ,
(CONVERT(INT, right(left('aksksksksjsjk&ct=100&rxp=1018&ls=1', 29),4)) )
select * from #temp
where Integ >918
drop table #temp
hope it helps you
answered Nov 8 at 10:40
Vaso Miruashvili
33
33
add a comment |
add a comment |
Ike White is a new contributor. Be nice, and check out our Code of Conduct.
Ike White is a new contributor. Be nice, and check out our Code of Conduct.
Ike White is a new contributor. Be nice, and check out our Code of Conduct.
Ike White is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53205251%2fmysql-select-from-text-column-with-filtering%23new-answer', 'question_page');
}
);
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password