473,396 Members | 1,786 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

can anyone solve this sql query?

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

Oct 16 '06 #1
4 1607
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."
Oct 16 '06 #2
Am 16 Oct 2006 00:47:31 -0700 schrieb hardik:

....
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 ........
If ',' is your separator you can use:
SELECT * FROM test12 WHERE `fid` = '1' or `fid` LIKE ('1,%') or
`fid` LIKE ('%,1,%') or `fid` LIKE ('%,1')

bye, Helmut
Oct 16 '06 #3
Thank you very much!
It works for me perfectly....
Kristian Damm Jensen wrote:
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."
Oct 16 '06 #4
Kristian Damm Jensen wrote:
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.
http://en.wikipedia.org/wiki/First_normal_form

You shouldn't store multiple values in a single column. Instead, change
your table to look like this:

id fid
-- ---
1 1
1 2
1 3
1 4
1 5
2 11
2 12
2 13
2 14
2 15

and then you can simply do

select * from test12 where fid = 1

You should also use column names that are more descriptive than 'id' and
'fid', e.g. 'SalesOrderHeaderID' and 'SalesOrderLineID'.
Oct 17 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: BVM | last post by:
Hi, All: I have this error. It seems execution time is too long. Actually the execution time is about 30 seconds(I tested in Query analyzer). How do I solve this problem? ...
2
by: pratchaya | last post by:
This is my sample error in my MySQL Log New value of fp=(nil) failed sanity check, terminating stack trace! Please read http://www.mysql.com/doc/en/Using_stack_trace.html and follow instructions...
7
by: Patrick Fisher | last post by:
Hi I have a table which Contains entries with RefCode field containing INVP or INVPD Common fields in each entry would be InvoiceNo, Total and PurTyp for example. You could have ...
45
by: salad | last post by:
I'm curious about your opinion on setting relationships. When I designed my first app in Access I'd go to Tools/Relationships and set the relationships. Over time I'd go into the window and see...
1
by: arun | last post by:
Query is too complex -------------------------------------------------------------------------------- Hi, I was trying to solve this problem since last two days but couldn't find any solution. ...
5
by: hardik | last post by:
hi friends i need help in this sql query i have table like, id fid __ _____ autonumber text and i am storing values like
2
by: gsreenathreddy | last post by:
Hi! Please solve this query in employee table in scott user i would like view the details of all the employees (empno, ename )who are working under which manager(mgr) .with his manager name...
6
by: fido19 | last post by:
Once upon a time, there lived a chimpanzee called Luycha Bandor (aka Playboy Chimp). Luycha was unhappily married to Bunty Mona, a short but cute little lady chimp. Luycha was tall and handsome –...
0
by: xwebmaster | last post by:
Hi Please help me solving this query.. I have 3 tables.. comm_propDB ID | User_ID | mls_num -----|---------------|--------------------- 2 | 2 | 5004 3 | 2 ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.