You are here: Re: can anyone solve this sql query? « MsSQL Server « IT news, forums, messages
Re: can anyone solve this sql query?

Posted by Kristian Damm Jensen on 10/16/06 10:48

hardik wrote:
> hi friends i need help in this sql query
>
> i have table like,
>
> id fid
> __ _____
> autonumber text
>
> and i am storing values like
>
> id fid
> ___________________________________
> 1 1,2,3,4,5
>
> 2 11,12,13,14,15
>
> now to find values i am using query
>
> sql = SELECT * FROM test12 WHERE `fid` LIKE ('%1%')
>
> only problem in this query is it is selecting 1 and 11 and i require
> only 1 as i am giving one in %1%
> now any one have answer of this question then plz plz tell me ........

It seems like you are querying a database, that is not even in 1NF - you are
up to your neck in trouble. Rather than working on a single query you should
reorganise your database.

This particular query can be solved by

select *
from test
where fid = '1' -- singleton
or fid like '1,%' -- beginning of line
or fid like '%,1,%' -- middle of line
or fid like '%,1' -- end of line

All of this assuming that you have no spaces in fid.

--
Regards,
Kristian Damm Jensen
"This isn't Jeopardy. Answer below the question."

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация