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
11 2300
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: -
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'
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 -
Select count(*) form table1 where name = 'nick' and year = '2007' and substr(phonenumber,1,3) = '234' and substr(phonenumber,1,4) = '2345';
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.
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'
thanks for the tips.
I change it to : -
SELECT count(*) FROM table1 WHERE name = 'nick' AND year = '2007' AND (substr(phonenumber,1,3) = '123' OR substr(phonenumber,1,4) = '1234' );
-
and it works fine.
Thanks again.
from
Nick
thanks for the tips.
I change it to : -
SELECT count(*) FROM table1 WHERE name = 'nick' AND year = '2007' AND (substr(phonenumber,1,3) = '123' OR substr(phonenumber,1,4) = '1234' );
-
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'
Heya, Nick.
Don't use SUBSTR in this query; it's not indexable. Use the LIKE keyword instead.
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
Heya, Nick.
Depends. What part of those numbers is significant?
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.
Heya, Nick.
pdmods. That's a good one.
Make sure your table is indexed by phone number, and then execute your query: -
SELECT
-
*
-
FROM
-
`table`
-
WHERE
-
(
-
`phone` LIKE '016%'
-
OR
-
`phone` LIKE '0146%'
-
OR
-
`phone` LIKE '01430%'
-
OR
-
`phone` LIKE '01431%'
-
)
-
By making use of the table's index, this query can be executed relatively quickly regardless of the number of rows.
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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,...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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,...
|
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...
|
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...
|
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,...
| |