| |
|
If this is your first visit, be sure to check out the FAQ by clicking the link above.
You may have to register before you can post: click the register link above to proceed.
To start viewing messages, select the forum that you want to visit from the selection below.
|
 |

09-09-11, 07:46
|
|
Registered User
|
|
Join Date: Sep 2011
Posts: 5
|
|
|
Search Query
|
|
Hello all,
I have a problem in building the query for search.
I have a table which contains a column X stores numerous values in each respective cell of a row.
For e.g.
HTML Code:
rows COLUMN X
1 120;132;143;154;165
2 122;134;543;566;
What I want to do is to make a query which search with a given range and return the rows which falls into the search
For e.g.
If I want to get the rows which contains values between 120 and 136 then it should return rows 1 and 2.
The datatype for Column X is varchar since each cell has to store numerous integers.
Please help me to get over this.
thanks
|
|

09-09-11, 07:53
|
|
SQL Consultant
|
|
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
|
|
what you are asking for is always going to be slow, slow, slow -- it will require a table scan
do a search for first normal form, and then do whatever you can to change the design of your tables so that each column contains only one value
you will thank me later 
|
|

09-09-11, 07:55
|
|
Registered User
|
|
Join Date: Sep 2011
Posts: 5
|
|
|
|
Hi,
Thanks for the reply
But I want it in this manner, sorry.
Is there a way to achieve it (may be using REGEXP) or is it possible to store a list of integers in a cell?
|
|

09-09-11, 08:39
|
|
SQL Consultant
|
|
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
|
|
REGEXP isn't going to help
if this design is so great, how come you find it so difficult to write a query to get what you want?
trust me, you will save yourself a ~lot~ of trouble by simply redesigning the table to conform to first normal form -- only one value any column
|
|

09-09-11, 08:58
|
|
Registered User
|
|
Join Date: Sep 2011
Posts: 5
|
|
Hi,
Thanks,
The problem is, there will be 100's of values as such that has to be stored in a row (separated by "," or ";" or any), I have just posted a sample and basic one. I don't think it is a wise idea to make 100's of columns and not sure how many are useful at each time of the data entry (the data might be more columns or may be less).
Obviously, one value in one column can solve the problem much more easy way. But the basic structure of the data is a crucial here.
|
|

09-09-11, 09:13
|
|
SQL Consultant
|
|
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
|
|
Quote:
Originally Posted by asd1234
I don't think it is a wise idea to make 100's of columns
|
you obviously still have not bothered to do any research on first normal form
if you had done so, you would have discovered that you do not need "100's of columns"
all good articles about first normal form also include hints about how to normalize a structure such as yours with repeating data values
change this design --
Code:
id columnX
1 120;132;143;154;165
2 122;134;543;566
to this --
Code:
id columnY
1 120
1 132
1 143
1 154
1 165
2 122
2 134
2 543
2 566
see? not "100's of columns" -- just one
|
|

09-09-11, 09:16
|
|
Registered User
|
|
Join Date: Sep 2011
Posts: 5
|
|
Thank you very much  , That is one good way of doing it.
But again it will be t0o many rows. How many rows a table can handle?
Is it possible that it can handle 200 million rows?
|
|

09-09-11, 09:20
|
|
SQL Consultant
|
|
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
|
|
|
|

09-09-11, 09:34
|
|
Registered User
|
|
Join Date: Sep 2011
Posts: 5
|
|
Thank you very much... you saved my day  .
|
|

09-25-11, 05:18
|
|
Registered User
|
|
Join Date: May 2010
Location: Hyderabd
Posts: 12
|
|
|
What about load on server?
Quote:
Originally Posted by asd1234
Thank you very much  , That is one good way of doing it.
But again it will be t0o many rows. How many rows a table can handle?
Is it possible that it can handle 200 million rows?
|
It is possible to store so many rows. But again the increase in number of rows will load server heavily. Isn't it?
|
|

09-25-11, 06:02
|
|
SQL Consultant
|
|
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
|
|
Quote:
Originally Posted by vibhavram
But again the increase in number of rows will load server heavily. Isn't it?
|
no, it isn't, not if you have appropriate indexes on your tables that optimize the queries that you need to run
note that the performance of data sitting in the database is 100%
in other words, it isn't the number of rows that causes performance problems, what really matters is whether a particular query can be properly optimized
because if you don't run any query, there is 0% server load
|
|

09-25-11, 06:52
|
|
Registered User
|
|
Join Date: May 2010
Location: Hyderabd
Posts: 12
|
|
Quote:
Originally Posted by r937
no, it isn't, not if you have appropriate indexes on your tables that optimize the queries that you need to run
note that the performance of data sitting in the database is 100%
in other words, it isn't the number of rows that causes performance problems, what really matters is whether a particular query can be properly optimized
because if you don't run any query, there is 0% server load
|
Can you suggest me a best online tutorial on database indexing?
|
|

09-25-11, 08:02
|
|
SQL Consultant
|
|
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
|
|
there are many excellent indexing tutorials, just google and you will find them
|
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|