Computer Webmaster Gaming Console Graphics Forum

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.

MK PitStop Main Earn $25 Earn Money Posting Extras Members Blogs Image Hosting User Pages
Go Back   Computer Webmaster Gaming Console Graphics Forum > Webmaster Forum > Website Coding > Database
Register FAQ/Rules Become A V.I.P. Member Search Today's Posts Mark Forums Read

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.

Google
Closed Thread
 
LinkBack Thread Tools Display Modes
Old 07-01-2007, 6:42 PM   #1
Rune
 
Rune's Avatar
 
Posts: n/a
My Photos: (0)

Banked:
MK Cash: $

I am Worth:
MK Cash: $
Donate

Recent Blog: None

Default Reverse like query?

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


 
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit!
Advertisements
Old 07-01-2007, 6:42 PM   #2
Stefan Rybacki
 
Stefan Rybacki's Avatar
 
Posts: n/a
My Photos: (0)

Banked:
MK Cash: $

I am Worth:
MK Cash: $
Donate

Recent Blog: None

Default Reverse like query?

-----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-----
 
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit!
Old 07-01-2007, 6:42 PM   #3
Rune
 
Rune's Avatar
 
Posts: n/a
My Photos: (0)

Banked:
MK Cash: $

I am Worth:
MK Cash: $
Donate

Recent Blog: None

Default Reverse like query?

"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


 
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit!
Old 07-01-2007, 6:42 PM   #4
Rune
 
Rune's Avatar
 
Posts: n/a
My Photos: (0)

Banked:
MK Cash: $

I am Worth:
MK Cash: $
Donate

Recent Blog: None

Default Reverse like query?

"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.


 
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit!
Old 07-01-2007, 6:43 PM   #5
Rune
 
Rune's Avatar
 
Posts: n/a
My Photos: (0)

Banked:
MK Cash: $

I am Worth:
MK Cash: $
Donate

Recent Blog: None

Default Reverse like query?

"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!


 
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit!
Old 07-01-2007, 6:43 PM   #6
Jerry Stuckle
 
Jerry Stuckle's Avatar
 
Posts: n/a
My Photos: (0)

Banked:
MK Cash: $

I am Worth:
MK Cash: $
Donate

Recent Blog: None

Default Reverse like query?

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
==================
 
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit!
Old 07-01-2007, 6:43 PM   #7
Rune
 
Rune's Avatar
 
Posts: n/a
My Photos: (0)

Banked:
MK Cash: $

I am Worth:
MK Cash: $
Donate

Recent Blog: None

Default Reverse like query?

"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


 
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit!
Old 07-01-2007, 6:43 PM   #8
Harald Fuchs
 
Harald Fuchs's Avatar
 
Posts: n/a
My Photos: (0)

Banked:
MK Cash: $

I am Worth:
MK Cash: $
Donate

Recent Blog: None

Default Reverse like query?

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, '%')
 
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit!
Old 07-01-2007, 6:43 PM   #9
Rune
 
Rune's Avatar
 
Posts: n/a
My Photos: (0)

Banked:
MK Cash: $

I am Worth:
MK Cash: $
Donate

Recent Blog: None

Default Reverse like query?

"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.


 
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit!
Featured Websites
Free Space
Free Space
Free Space Free Space
Closed Thread
Tags: ,




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

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




All times are GMT +1. The time now is 4:51 AM.


Powered by: vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO 3.0.0
Cheap Computers
MK PitStop Copyright 2005 - 2008

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98