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.

 
Go Back  dBforums > Database Server Software > MySQL > Search Query

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-09-11, 07:46
asd1234 asd1234 is offline
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
Reply With Quote
  #2 (permalink)  
Old 09-09-11, 07:53
r937 r937 is offline
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
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 09-09-11, 07:55
asd1234 asd1234 is offline
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?
Reply With Quote
  #4 (permalink)  
Old 09-09-11, 08:39
r937 r937 is offline
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
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #5 (permalink)  
Old 09-09-11, 08:58
asd1234 asd1234 is offline
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.
Reply With Quote
  #6 (permalink)  
Old 09-09-11, 09:13
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
Quote:
Originally Posted by asd1234 View Post
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
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #7 (permalink)  
Old 09-09-11, 09:16
asd1234 asd1234 is offline
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?
Reply With Quote
  #8 (permalink)  
Old 09-09-11, 09:20
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
yes it is possible
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #9 (permalink)  
Old 09-09-11, 09:34
asd1234 asd1234 is offline
Registered User
 
Join Date: Sep 2011
Posts: 5
Thank you very much... you saved my day .
Reply With Quote
  #10 (permalink)  
Old 09-25-11, 05:18
vibhavram vibhavram is offline
Registered User
 
Join Date: May 2010
Location: Hyderabd
Posts: 12
What about load on server?

Quote:
Originally Posted by asd1234 View Post
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?
Reply With Quote
  #11 (permalink)  
Old 09-25-11, 06:02
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
Quote:
Originally Posted by vibhavram View Post
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
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #12 (permalink)  
Old 09-25-11, 06:52
vibhavram vibhavram is offline
Registered User
 
Join Date: May 2010
Location: Hyderabd
Posts: 12
Quote:
Originally Posted by r937 View Post
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?
Reply With Quote
  #13 (permalink)  
Old 09-25-11, 08:02
r937 r937 is offline
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
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

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