Question:
Sql query for string?
PK
2012-08-28 23:52:30 UTC
I have a table Name tab1 there I have two field name f1 and f2.
Tab1 is like
f1 ..... f2
----------------
10 ... 9
200 ... 300
5000 ... 600
100 .... 199
1909 .... 1999
100 .... 199
1000 .... 1999
2000 .... 2787
....
......
I want to search all the field having match the 1st character of both the field.
o/p:
f1 .... f2
============
100 .... 199
1000 .... 1999
2000 .... 2787
1909 .... 1999

Can anyone tell me wht query I need to run?
Thanks a ton.
Six answers:
anonymous
2012-08-29 01:21:03 UTC
select f1,f2

from tab1

where SUBSTR(f1,1,1)=SUBSTR(f2,1,1)



substr is used to take a part of the whole string.
?
2012-08-29 00:39:26 UTC
How is that going to work. If you're just matching the first character of both fields, then 100 could match either 199 or 1999 or 1000 could match 199 or 1999. I think your logic might be flawed.
Serge M
2012-08-29 08:57:51 UTC
select distinct f1,f2

from tab1

where left(f1, 1) = left(f2, 1)
firkins
2016-08-01 06:46:44 UTC
You'll be able to ought to inform us what you wish to have first. All documents where field meets the criterion of . The where clause refers to the value of a subject or fields.
DigitalGrep
2012-08-29 03:43:22 UTC
select * from tab1 where substr(f1,1,1)=substr(f2,1,1,);
maung
2012-08-29 00:01:02 UTC
yes


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...