Alternative to MySQL’s LIMIT Command

December 20th, 2009 Pierre Buckley 2 comments

I recently ran into the situation where I needed to create a query in MySQL that counted up to n rows from a result set. I scoffed at the challenge and proceeded to go for the one tool I thought could do the job – MySQL's LIMIT command. Unfortunately, the result I got was not what I had expected.


The Problem

If I had a table like below: 

 

Employees Table
id First Name Last Name Salary
1 John Brown 150,000
2 Pierre Buckley 200,000
3 Hillary White 170,000
4 Ferdinand McBean 100,000

 

I would expect that the following query would return a count of 1.
 

select count(*) from Employees limit 0,1

 

Instead, I got a value of 4 for the count which would be representative of all the rows in the table. And so it seems, that the LIMIT command only applies to the single record that is returned when the count aggregate function is used. This was useless to me.


The Solution

I went searching for a solution on Google and came across this post on stackoverflow where someone had asked a similar question. In one of the solutions that were given, there was mention of how it is implemented on Oracle. That led me to test it out in MySQL and it worked. Here's what I did.
 

select count(*) from (select * from Employees limit 1,0) as emp_table 

 

This worked like a charm, albeit was a bit messy. I could live with it though as this was only being done for an assignment I had to complete for school. As such, the possible resulting performance penalty that may be associated with this method was not an issue. Please note that you must define an alias for your sub query.

I hope this information is useful to someone out there. If it is, please don't hesitate to comment. Chao.

Categories: MySQL Tags: , , , ,

ASP.NET from Scratch Tutorial Series

December 14th, 2009 Pierre Buckley 1 comment

Very good screencast that introduces ASP.Net. Authored by Jeremy McPeak and hosted at Nettuts. So far there are only two lessons available. I will continue to update this post as more becomes available.

 

ASP.NET from Scratch: Lesson 1

 

ASP.NET from Scratch: Lesson 2

Categories: ASP.Net Tags: , ,

I Am Back!

September 30th, 2009 Pierre Buckley No comments

After being absent for way too long, I decided to dust off this blog and try running with it again. I must say that I am much more experienced than when I first started this blog and I have so much more to share.

I will be sharing this information with everyone in the coming weeks. I thought I would start thing off by writing a tutorial to make your own blog, albeit will only have the bare minimum features. So you can look out for that.

Until then, I will be identifying other topics that I can write on. There are so many in my head that I want to share. Please join me next week for Contructing Your Own Blog post.

Categories: Uncategorized Tags:

Windows Live Writer

August 6th, 2008 Pierre Buckley No comments

Ok, so I came across Windows Live Writer today. I am publishing this post by using it. I must say that I am impressed by it and now believe, at least, I will be able to update my blog more often. I tire of logging in to Blogger and creating a new post. It's too tedious.

Now that I have Live Writer, I can write the post from a desktop application. Much easier. You should check it out. It's been too long since I can say that I am proud of Microsoft. The guys behind this application gets two thumbs up from me.

Snapshot

Starting ASP.NET Programming

March 8th, 2007 Pierre Buckley 2 comments

Okay, I haven't updated this blog in a while. The reason is i am bogged down with tons of school work. At the moment, I have being doing a lot of ASP.Net and thought that I would just write this quick guide to help the noobs out there to get started in programming with ASP.Net. As always, you need to have some prerequisite knowledge and tools to get started. Read on…

Prerequisite Knowledge

  • Knowledge of VB.Net / C#.Net or J#.Net (necessary :( )
  • Knowledge in using Visual Studio.Net (not necessary :) )

ASP.Net is a great technology. The catch is that it has to be written in one of Microsoft's Visual programing languages. If you have no knowledge of any, then i suggest you start with VB.Net. It is the easiest to grasp and still as powerful as its siblings. Also, all my future ASP.Net tutorials or guides will be 100% VB.Net only.

Being familiar with a previous version of Visual Studio would also be an asset but not necessary. You can get around the IDE in no time as it is user friendly, however, if you are a noob then go see the Visual Web Developer 2005 Express Edition Feature Tour.

Prerequisite Tools

While Visual Studio Developer 2005 Express Edition is a great tool for creating ASP.Net pages, it does have it's limitations. What, you thought Microsoft would pity us startup developers with empty pockets? The major limitation is that you cant publish your website from the IDE like in Visual Studio 2005. Also, you have a limited set of features, but this will not hinder your exploration ofthe wonderful world of ASP.Net. Also make sure to get the Service Pack 1 available for download.

SQL Server 2005 Express Edition is another great tool by M$. It's like an enterprise level Microsoft Access. Thats right, its a Database Management System. It's good to have when your ASP.Net website will persist information or use information from a data source. For example, you can make a website that gives a list of countries and their corresponding area codes, which you can make available from a drop down list. The drop down list can retrieve the information from SQL Servers' database when the page loads. This is referred to as data binding. There are, of course, lots of other uses, so it would be an asset to get this.

In conclusion, I have to say if you follow through with learning ASP.Net, you are making a wise decision. It's easy to use, in demand and and will prove to be a great weapon in your arsenal as a web developer. After you think that you have grasped all the concepts and have a fairly strong command of the VB.Net language, you can go to Microsofts Coding4Fun website to see the works of others, inspire yourself and sharpen your skills. By the way, if you are shady in your knowledge of what ASP.Net is, then i suggest you get an overview knowledge at Wikipedia.

An Introduction

January 10th, 2007 Pierre Buckley No comments

I thought I would kick of this blog with an introduction of myself. My name is Pierre Buckley and I am a programmer. I consider myself as a novice even though I have experiences in more than four computer programming languages…go figure. Anyways, I believe to better myself as a programmer, I would have to venture on a journey of research to uncover the mysteries of programming. I have created this blog to share my findings and knowledge with other programmers like myself.

I hope that my hard work will be of use to someone out there. Currently I am dabbling in VB.Net and ASP.Net. I do however fool around with C and C++ since they are my favourite programming languages and maybe a little Java when I feel like. I am aspiring to pick up PHP and RUBY in the near future.

If anyone has any links to helpful resources that I may use, please feel free to reply to this post. Thanks in advance.

Categories: Uncategorized Tags: