![]() |
|
Welcome to the Computer Webmaster Gaming Console Graphics Forum forums. You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today! If you have any problems with the registration process or your account login, please contact contact us. |
| |||||||
| Database Database problems or need to ask a question? maybe something to do with sql injections or a database software question. Database topics cover MySQL, PostgreSQL, Oracle, SQL Server or anything else related to databases. |
![]() |
| | LinkBack | Thread Tools | Display Modes |
| | #1 | ||
| I have some problems figuring this one out. How do I put together a query that selects those rows in which a field contains a substring of another given string. e.g. table test (test varchar(255)) row1: this is a test row2: test row3: a test row4: that If I have a string called "a test", then I want to select row 1 + 3, but not 2 and 4. thanks /Rune | |||
| Advertisements |
| | #2 | ||
| -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Rune schrieb: > I have some problems figuring this one out. How do I put together a query > that selects those rows in which a field contains a substring of another > given string. > > e.g. > > table test (test varchar(255)) > > row1: this is a test > row2: test > row3: a test > row4: that > > If I have a string called "a test", then I want to select row 1 + 3, but not > 2 and 4. > > thanks > /Rune > > SELECT * FROM table WHERE test LIKE '%a test%' Regards Stefan -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.2 (MingW32) iD8DBQFD2hQGyeCLzp/JKjARAgcKAJ9bnreVPkAexS77/7/HhmgKQc0oqgCdGvCS Gy/hlNFk38SepsZgCSxPtaU= =V8jz -----END PGP SIGNATURE----- | |||
| | #3 | ||
| "Stefan Rybacki" <stefan.rybacki@gmx.net> skrev i en meddelelse news:43uig6F1pje2gU1@individual.net... > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > Rune schrieb: >> I have some problems figuring this one out. How do I put together a query >> that selects those rows in which a field contains a substring of another >> given string. >> >> e.g. >> >> table test (test varchar(255)) >> >> row1: this is a test >> row2: test >> row3: a test >> row4: that >> >> If I have a string called "a test", then I want to select row 1 + 3, but >> not >> 2 and 4. >> >> thanks >> /Rune >> >> > > SELECT * FROM table WHERE test LIKE '%a test%' > > Regards > Stefan Dang! I put the question wrong. I keep mixing it up, because it's the oppositite of what I usally would need. I need to return all those rows where all the field is in the given string. It should return rows: 2+3, but not 1,4 1) "this is a test" is not part of "a test" : FAULT 2) "test" is part of "a test" : OK 3) "a test" is part of "a test" : OK 4) "that" is not part of "a test": FAULT | |||
| | #4 | ||
| "Rune" <slam@slam.slam> skrev i en meddelelse news:43da150b$0$15788$14726298@news.sunsite.dk... > "Stefan Rybacki" <stefan.rybacki@gmx.net> skrev i en meddelelse > news:43uig6F1pje2gU1@individual.net... >> -----BEGIN PGP SIGNED MESSAGE----- >> Hash: SHA1 >> >> Rune schrieb: >>> I have some problems figuring this one out. How do I put together a >>> query >>> that selects those rows in which a field contains a substring of another >>> given string. >>> >>> e.g. >>> >>> table test (test varchar(255)) >>> >>> row1: this is a test >>> row2: test >>> row3: a test >>> row4: that >>> >>> If I have a string called "a test", then I want to select row 1 + 3, but >>> not >>> 2 and 4. >>> >>> thanks >>> /Rune >>> >>> >> >> SELECT * FROM table WHERE test LIKE '%a test%' >> >> Regards >> Stefan > > Dang! I put the question wrong. I keep mixing it up, because it's the > oppositite of what I usally would need. I need to return all those rows > where all the field is in the given string. It should return rows: 2+3, > but not 1,4 > > 1) "this is a test" is not part of "a test" : FAULT > 2) "test" is part of "a test" : OK > 3) "a test" is part of "a test" : OK > 4) "that" is not part of "a test": FAULT Something like this: SELECT * from test WHERE "a test" like %test%; But this won't work. | |||
| | #5 | ||
| "Rune" <slam@slam.slam> skrev i en meddelelse news:43da1619$0$15785$14726298@news.sunsite.dk... > "Rune" <slam@slam.slam> skrev i en meddelelse > news:43da150b$0$15788$14726298@news.sunsite.dk... >> "Stefan Rybacki" <stefan.rybacki@gmx.net> skrev i en meddelelse >> news:43uig6F1pje2gU1@individual.net... >>> -----BEGIN PGP SIGNED MESSAGE----- >>> Hash: SHA1 >>> >>> Rune schrieb: >>>> I have some problems figuring this one out. How do I put together a >>>> query >>>> that selects those rows in which a field contains a substring of >>>> another >>>> given string. >>>> >>>> e.g. >>>> >>>> table test (test varchar(255)) >>>> >>>> row1: this is a test >>>> row2: test >>>> row3: a test >>>> row4: that >>>> >>>> If I have a string called "a test", then I want to select row 1 + 3, >>>> but not >>>> 2 and 4. >>>> >>>> thanks >>>> /Rune >>>> >>>> >>> >>> SELECT * FROM table WHERE test LIKE '%a test%' >>> >>> Regards >>> Stefan >> >> Dang! I put the question wrong. I keep mixing it up, because it's the >> oppositite of what I usally would need. I need to return all those rows >> where all the field is in the given string. It should return rows: 2+3, >> but not 1,4 >> >> 1) "this is a test" is not part of "a test" : FAULT >> 2) "test" is part of "a test" : OK >> 3) "a test" is part of "a test" : OK >> 4) "that" is not part of "a test": FAULT > > Something like this: SELECT * from test WHERE "a test" like %test%; > But this won't work. select * from test where test in ("a test") : returns row 3) but not 2) select * from test where %test% in ("a test"): is syntax error Alas! | |||
| | #6 | ||
| Rune wrote: > I have some problems figuring this one out. How do I put together a query > that selects those rows in which a field contains a substring of another > given string. > > e.g. > > table test (test varchar(255)) > > row1: this is a test > row2: test > row3: a test > row4: that > > If I have a string called "a test", then I want to select row 1 + 3, but not > 2 and 4. > > thanks > /Rune > > SELECT * FROM table WHERE data LIKE '%a test'; http://dev.mysql.com/doc/refman/5.1/...functions.html -- ================== Remove the "x" from my email address Jerry Stuckle JDS Computer Training Corp. jstucklex@attglobal.net ================== | |||
| | #7 | ||
| "Jerry Stuckle" <jstucklex@attglobal.net> skrev i en meddelelse news:1_-dnfVB6qcXgUfeRVn-ow@comcast.com... > Rune wrote: >> I have some problems figuring this one out. How do I put together a query >> that selects those rows in which a field contains a substring of another >> given string. >> >> e.g. >> >> table test (test varchar(255)) >> >> row1: this is a test >> row2: test >> row3: a test >> row4: that >> >> If I have a string called "a test", then I want to select row 1 + 3, but >> not 2 and 4. >> >> thanks >> /Rune > > > SELECT * FROM table WHERE data LIKE '%a test'; > > http://dev.mysql.com/doc/refman/5.1/...functions.html Nope. I'm sorry. I put the question wrong. I keep mixing it up, because it's the oppositite of what I usally would need. I need to return all those rows where all of the field is in the given string. It should return rows: 2+3, but not 1,4 1) "this is a test" is not part of "a test" : FAULT 2) "test" is part of "a test" : OK 3) "a test" is part of "a test" : OK 4) "that" is not part of "a test": FAULT Something like SELECT * from test WHERE "a test" like %test%; - but that doesn't work on MySQL | |||
| | #8 | ||
| In article <43da1c84$0$15788$14726298@news.sunsite.dk>, "Rune" <slam@slam.slam> writes: >>> Dang! I put the question wrong. I keep mixing it up, because it's the >>> oppositite of what I usally would need. I need to return all those rows >>> where all the field is in the given string. It should return rows: 2+3, >>> but not 1,4 >>> >>> 1) "this is a test" is not part of "a test" : FAULT >>> 2) "test" is part of "a test" : OK >>> 3) "a test" is part of "a test" : OK >>> 4) "that" is not part of "a test": FAULT >> >> Something like this: SELECT * from test WHERE "a test" like %test%; >> But this won't work. > select * from test where test in ("a test") : returns row 3) but not 2) > select * from test where %test% in ("a test"): is syntax error Use the following: SELECT whatever FROM test WHERE 'a test' LIKE concat('%', test, '%') | |||
| | #9 | ||
| "Harald Fuchs" <hf0923x@protecting.net> skrev i en meddelelse news:87d5idrdq5.fsf@srv.protecting.net... > In article <43da1c84$0$15788$14726298@news.sunsite.dk>, > "Rune" <slam@slam.slam> writes: > >>>> Dang! I put the question wrong. I keep mixing it up, because it's the >>>> oppositite of what I usally would need. I need to return all those rows >>>> where all the field is in the given string. It should return rows: 2+3, >>>> but not 1,4 >>>> >>>> 1) "this is a test" is not part of "a test" : FAULT >>>> 2) "test" is part of "a test" : OK >>>> 3) "a test" is part of "a test" : OK >>>> 4) "that" is not part of "a test": FAULT >>> >>> Something like this: SELECT * from test WHERE "a test" like %test%; >>> But this won't work. > >> select * from test where test in ("a test") : returns row 3) but not 2) >> select * from test where %test% in ("a test"): is syntax error > > Use the following: > > SELECT whatever > FROM test > WHERE 'a test' LIKE concat('%', test, '%') Yes! Just what I need. Thanks. | |||
| Featured Websites | ||||
|
![]() |
| Tags: query, reverse |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| php/mysql query insert values into enters the records in reverse order | Techie Guy | Database | 14 | 07-01-2007 6:24 PM |
| ***CAR REVERSE SENSOR SUPPLIER | Is | Car audio | 7 | 06-17-2007 3:07 PM |
| cvs: pear /MDB2 package_oci8.php /MDB2/MDB2/Driver/Reverse oci8.php | Lorenzo Alberton | Pear | 0 | 05-20-2007 7:42 PM |
| cvs: pear /MDB2 package_mssql.php /MDB2/MDB2/Driver/Reverse mssql.php | Lorenzo Alberton | Pear | 0 | 05-20-2007 7:42 PM |
| MDB2 ibase Reverse: strange case problem | Alessandro Pasotti | Pear | 3 | 05-20-2007 6:34 PM |
| Featured Websites | ||||
|