473,396 Members | 1,918 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.

search for keyword in table

254 100+
i have a table with some column, one of the column is phone number.

so if i want to count the phone number start with 234xxxxxx and 2345xxxxx ...how to do it with sql query statement?

like this,
Expand|Select|Wrap|Line Numbers
  1. select count(*) from table1 where phonenumber = 234xxxx and 2345xxxxx
  2.  
what is the keyword for it ?

i'm stuck.
pls help
from
Nick
Sep 18 '07 #1
11 2300
amitpatel66
2,367 Expert 2GB
i have a table with some column, one of the column is phone number.

so if i want to count the phone number start with 234xxxxxx and 2345xxxxx ...how to do it with sql query statement?

like this,

select count(*) from table1 where phonenumber = 234xxxx and 2345xxxxx

what is the keyword for it ?

i'm stuck.
pls help
from
Nick
Check below Queries:
Expand|Select|Wrap|Line Numbers
  1. SELECT COUNT(*) FROM table1 WHERE phonenumber LIKE '234%' OR phonenumber LIKE '2345%'
(or)
Expand|Select|Wrap|Line Numbers
  1. SELECT COUNT(*) FROM table WHERE SUBSTR(phonenumber,1,3) = '234' OR SUBSTR(phonenumber,1,4) = '2345'
Sep 18 '07 #2
nickyeng
254 100+
Check below Queries:

SELECT COUNT(*) FROM table1 WHERE phonenumber LIKE '234%' OR phonenumber LIKE '2345%'

(or)

SELECT COUNT(*) FROM table WHERE SUBSTR(phonenumber,1,3) = '234' OR SUBSTR(phonenumber,1,4) = '2345'
can i use AND instead of OR ?

or

can i use
Expand|Select|Wrap|Line Numbers
  1. Select count(*) form table1 where name = 'nick' and year = '2007' and substr(phonenumber,1,3) = '234' and substr(phonenumber,1,4) = '2345';
Sep 18 '07 #3
r035198x
13,262 8TB
can i use AND instead of OR ?

or

can i use

Select count(*) form table1 where name = 'nick' and year = '2007' and substr(phonenumber,1,3) = '234' and substr(phonenumber,1,4) = '2345';
Guys let's all remember to use [code=mysql] tags when posting our code.
@OP Why don't you try them and see what happens? You'll learn better that way. Reading a tutorial is also not a bad idea.
Sep 18 '07 #4
amitpatel66
2,367 Expert 2GB
can i use AND instead of OR ?

or

can i use

Select count(*) form table1 where name = 'nick' and year = '2007' and substr(phonenumber,1,3) = '234' and substr(phonenumber,1,4) = '2345';

only one condiition substr(phonenumber,1,3) = '234' is enough in the query. This will give you all the records whose first 3 digits start with '234'
Sep 18 '07 #5
nickyeng
254 100+
thanks for the tips.

I change it to :

Expand|Select|Wrap|Line Numbers
  1. SELECT count(*) FROM table1 WHERE name = 'nick' AND year = '2007' AND (substr(phonenumber,1,3) = '123' OR substr(phonenumber,1,4) = '1234' );
  2.  
and it works fine.
Thanks again.
from
Nick
Sep 18 '07 #6
amitpatel66
2,367 Expert 2GB
thanks for the tips.

I change it to :

Expand|Select|Wrap|Line Numbers
  1. SELECT count(*) FROM table1 WHERE name = 'nick' AND year = '2007' AND (substr(phonenumber,1,3) = '123' OR substr(phonenumber,1,4) = '1234' );
  2.  
and it works fine.
Thanks again.
from
Nick
Your query will work fine but the last condition in your query is not required.
substr(phonenumber,1,3) = '123' will itself return the phone number which starts with 123. This condition will also return the phone number with 1234 because the first three digits are 123 and it satisfies this condition substr(phonenumber,1,3) = '123'
Sep 18 '07 #7
pbmods
5,821 Expert 4TB
Heya, Nick.

Don't use SUBSTR in this query; it's not indexable. Use the LIKE keyword instead.
Sep 18 '07 #8
nickyeng
254 100+
Your query will work fine but the last condition in your query is not required.
substr(phonenumber,1,3) = '123' will itself return the phone number which starts with 123. This condition will also return the phone number with 1234 because the first three digits are 123 and it satisfies this condition substr(phonenumber,1,3) = '123'
what if i have these number :

016
0146
01430
01431
Sep 19 '07 #9
pbmods
5,821 Expert 4TB
Heya, Nick.

Depends. What part of those numbers is significant?
Sep 19 '07 #10
nickyeng
254 100+
hi pdmods

my records contains 60thousands and keep increasing...
it has number in each record.

i check the number in each record by that number starts with 016, 0146, 01430, 01431; and increase counter.

and then i have another counter for another group which has to check/search number by starts with 6012, 60146.

This is what i want.
Sep 19 '07 #11
pbmods
5,821 Expert 4TB
Heya, Nick.

pdmods. That's a good one.

Make sure your table is indexed by phone number, and then execute your query:
Expand|Select|Wrap|Line Numbers
  1. SELECT
  2.         *
  3.     FROM
  4.         `table`
  5.     WHERE
  6.     (
  7.             `phone` LIKE '016%'
  8.         OR
  9.             `phone` LIKE '0146%'
  10.         OR
  11.             `phone` LIKE '01430%'
  12.         OR
  13.             `phone` LIKE '01431%'
  14.     )
  15.  
By making use of the table's index, this query can be executed relatively quickly regardless of the number of rows.
Sep 19 '07 #12

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Phil Powell | last post by:
The table already has a fulltext index and from there I can use the MySQL fulltext search query to get results as well as the relevancy score. The problem I have is that MySQL has a default...
1
by: Les Juby | last post by:
A year or two back I needed a search script to scan thru HTML files on a client site. Usual sorta thing. A quick search turned up a neat script that provided great search results. It was fast,...
2
by: amoona | last post by:
Hi… I’m doing a search page form my work for their library. Since this is the first time I work with ASP I’m facing some problems. Each library item has different search data, I was able to...
2
by: Torfi Sackbatten | last post by:
Hi Everyone, I´m asked to "speed up" a keyword search based on MySQL. The material i´m given to work with is a quite large MySQL table with 1.5 mio rows, defined something like: CREATE TABLE...
3
by: Bryan | last post by:
I'm looking for some advice on the best way to execute a complicated search on my eCommerce web site. My example here is much simpler than the real thing, but it should be enough to get the point...
19
by: bb nicole | last post by:
Below is my search engine for job portal which jobseeker can find the job through quick search. But it cant work... Is it mysql query got problem?? Thanx.. Interface <html> <head> <title>UMS...
5
by: mforema | last post by:
Hi Everyone, I want to search records by typing in multiple keywords. I currently have a search form. It has a combo box, text box, Search command button, and a subform. The combo box lists the...
2
by: rlemusic | last post by:
Hi everybody, I’m creating a database in Access (I believe it’s 2000) to catalogue items in the archives of a small museum. I’m a total n00b as far as using Access goes, but by looking at some...
5
by: kanley | last post by:
I have a main table with a text description field. In this field, its populated with a string of data. I need to identify from this string of data the name of the vendor using some keywords. I...
12
by: iahamed | last post by:
Hi Everyone, I got two parts of my advance search to work, I am running out of Logic to connect the third. My mind is in swing! Pleaseeeeeeeee Help me. I have 3 Fiels to search, the First two...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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.