Welcome to dbForumz.com!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

Missing Nubers

 
   Database Forums (Home) -> PHP SQL RSS
Next:  Importing multiple csv files  
Author Message
Brian

External


Since: Dec 03, 2007
Posts: 3



(Msg. 1) Posted: Tue Dec 11, 2007 7:58 pm
Post subject: Missing Nubers
Archived from groups: alt>php, others (more info?)

Hi all



Sorry for the cross postings but there may be a simple solution that can be
done in SQL.

I am trying to work out if there are missing numbers in a range stored in a
database table.



The first problem is the number range is prefixed with UR (eg UR12345), what
I need to

try and work out it are there any numbers in the range missing, the range
should be from

UR1000 to UR30000, what the best way to try and work this out?



Thanks



Brian





--------------------------------------------------------------------------------

I am using the free version of SPAMfighter for private users.
It has removed 1005 spam emails to date.
Paying users do not have this message in their emails.
Try SPAMfighter for free now!

 >> Stay informed about: Missing Nubers 
Back to top
Login to vote
Jerry Stuckle

External


Since: Aug 11, 2004
Posts: 1367



(Msg. 2) Posted: Tue Dec 11, 2007 10:48 pm
Post subject: Re: Missing Nubers [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Brian wrote:
> Hi all
>
>
>
> Sorry for the cross postings but there may be a simple solution that can be
> done in SQL.
>
> I am trying to work out if there are missing numbers in a range stored in a
> database table.
>
>
>
> The first problem is the number range is prefixed with UR (eg UR12345), what
> I need to
>
> try and work out it are there any numbers in the range missing, the range
> should be from
>
> UR1000 to UR30000, what the best way to try and work this out?
>
>
>
> Thanks
>
>
>
> Brian
>
>

This is a bit off target for alt.php. But you could also try a
newsgroup for your database, i.e. comp.databases.(your_rdbms_here).

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex DeleteThis @attglobal.net
==================

 >> Stay informed about: Missing Nubers 
Back to top
Login to vote
Steve

External


Since: Oct 18, 2006
Posts: 235



(Msg. 3) Posted: Wed Dec 12, 2007 11:26 am
Post subject: Re: Missing Nubers [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

"Brian" wrote in message


> I am trying to work out if there are missing numbers in a range stored in
> a database table.

SELECT a.Id + 1 Missing
FROM foo a
LEFT JOIN foo b
ON b.Id = a.Id + 1
WHERE b.Id IS NULL

(that's one way...and faster than working over a resultset in php to get the
same result)

> The first problem is the number range is prefixed with UR (eg UR12345),
> what I need to
>
> try and work out it are there any numbers in the range missing, the range
> should be from
>
> UR1000 to UR30000, what the best way to try and work this out?

cast the result of right(a, length(a) - 2) as an integer and plug that into
the query above...changing the names to your appropriate tables and fields.
 >> Stay informed about: Missing Nubers 
Back to top
Login to vote
Steve

External


Since: Oct 18, 2006
Posts: 235



(Msg. 4) Posted: Wed Dec 12, 2007 11:27 am
Post subject: Re: Missing Nubers [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

"Jerry Stuckle" wrote in message

> Brian wrote:
>> Hi all
>>
>>
>>
>> Sorry for the cross postings but there may be a simple solution that can
>> be done in SQL.
>>
>> I am trying to work out if there are missing numbers in a range stored in
>> a database table.
>>
>>
>>
>> The first problem is the number range is prefixed with UR (eg UR12345),
>> what I need to
>>
>> try and work out it are there any numbers in the range missing, the
>> range should be from
>>
>> UR1000 to UR30000, what the best way to try and work this out?
>>
>>
>>
>> Thanks
>>
>>
>>
>> Brian
>>
>>
>
> This is a bit off target for alt.php. But you could also try a newsgroup
> for your database, i.e. comp.databases.(your_rdbms_here).

it looks like he's well aware of the ot-ishness of the post. can't you take
the whole 30 seconds it takes to write the damn thing! this ain't rocket
science you know.
 >> Stay informed about: Missing Nubers 
Back to top
Login to vote
J.O. Aho

External


Since: Dec 01, 2003
Posts: 397



(Msg. 5) Posted: Wed Dec 12, 2007 1:58 pm
Post subject: Re: Missing Nubers [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Brian wrote:
> Hi all
>
>
>
> Sorry for the cross postings but there may be a simple solution that can be
> done in SQL.
>
> I am trying to work out if there are missing numbers in a range stored in a
> database table.
>
>
>
> The first problem is the number range is prefixed with UR (eg UR12345), what
> I need to
>
> try and work out it are there any numbers in the range missing, the range
> should be from
>
> UR1000 to UR30000, what the best way to try and work this out?

As far as I know, you would need to do

for($i=1000;$i<=30000;$i++) {
$query="SELECT count(*) FROM table WHERE column='UR{$i}'";
$res=mysqli->query($query);
if(!$res->num_rows) {
echo "Missing number is UR{$i}\n";
}
}


--

//Aho
 >> Stay informed about: Missing Nubers 
Back to top
Login to vote
Steve

External


Since: Oct 18, 2006
Posts: 235



(Msg. 6) Posted: Wed Dec 12, 2007 1:58 pm
Post subject: Re: Missing Nubers [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

"J.O. Aho" wrote in message


> for($i=1000;$i<=30000;$i++) {
> $query="SELECT count(*) FROM table WHERE column='UR{$i}'";
> $res=mysqli->query($query);
> if(!$res->num_rows) {
> echo "Missing number is UR{$i}\n";
> }
> }

aho, i'm not going to say that's a crazy way to do it...but, just look at
the resources you're wasting! you really want to run a query for *every*
iteration? even this is more attractive...but butt-ugly:

$sql = array();
for ($i = 1000; $i <= 3000; $i++)
{
$sql[] = "
SELECT 'UR" . $i . " Id ,
COUNT(*) Missing
FROM table
WHERE column = 'UR" . $i . "
";
}
$sql = "
SELECT *
FROM
(
" . implode(' UNION', $sql) . "
)
WHERE Missing = 0
";
$query = mysqli->query($sql);
echo '<pre>' . print_r($query, true) . '</pre>';
 >> Stay informed about: Missing Nubers 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
One query and problem LIMIT - Hi all, I have 2 tables: articles and categories articles table: ------------ articleid categoryid name categories table: --------------- categotyid name description I want to get the last entred 5 articles for each category with one quey: like..

multiple select but ......php/mysql/html - hello, Maybe someone can help me out with this one where i am stuck where i solve this in html or other code? html/php and mysql using in a html form: <tr> <td><?php echo"<font face=$b_fontface size=$b_fontsize&...

Create Tabel - Hi I am having some problems using MySQL. I am trying to create a table in a database using the query "CREATE TABLE enquiries (id int(6) NOT NULL auto_increment,name varchar(80) NOT NULL,email varchar(80) NOT NULL,company varchar(80) NOT NULL,tele...

Join same columns from two tables - Hi, I have two tabels. Table a and table b. Both tables habe a column named x. I need a sql statement, wich transfers the colum from a and b in the same colum in the resultset. Example: table a, column x cat dog duck human table b, column x cat duc...

Execute item from array - I have an array, say something like this (to build a form): $commands = array( "Start Date" => "build_date('startdate')", "End Date" => "build_date('enddate')" ); Only it will have many more entries. I want...
   Database Forums (Home) -> PHP SQL All times are: Pacific Time (US & Canada)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]