Posts Tagged ‘ms-sql’
SQL – Filtering WHERE condition on two rows
I received the following question a couple of days ago from a programmer using the “Ask a Question” form which you can access from the menu of this blog:
Given the following table:
| Name | Language |
| Nikhil | Hindi |
| Nikhil | English |
| Kisu | Hindi |
| Kisu | English |
| Rakesh | Hindi |
| Kousik | Bangali |
How do I select names of persons who know both Hindi and English?
In this table, that query should return Nikhil and Kisu.
Random in SQL – SQL For Programmers
Last week I had an interesting assignment: Given a specific record, randomly retrieve three related records from the database.
Naturally, as a programmer, I started looking for the SQL random function. Which I found.
But even as I was searching for how to use that function, I was thinking to myself, “How am I going to structure things in such a way so as to randomly select the records once I have the function? It isn’t like I can retrieve the records into an array and then select them out. Am I going to have to retrieve them into a temp table?”
SQL WHILE – SQL For Programmers
The IF statement we looked at on Tuesday was pretty tame compared to the WHILE construct.
Actually, the main thing you need to keep in mind is that WHILE is all you have. There is no such thing as a FOR loop or a DO WHILE loop. So, you have to force WHILE to do those for you.
The basic syntax of WHILE looks like this:
Basic SQL Commands – SQL For Programmers
Before we get into the specifics of the commands that can be used within a stored procedure, I think it would be helpful to review some of the more basic commands that we can use that don’t really need a whole lot of discussion.
I know I said I wasn’t going to spend a lot of time on the basics, but my research indicates that a lot of people are searching for basic sql commands and very few sites are addressing that issue specifically.
So, if this is unhelpful to you, just consider this Dave’s SEO experiment.
SQL For Programmers – Stored Procedure Basics
Now that we’ve established a reason for using them, let’s continue with the basic syntax of the stored procedure. I think you’ll find that it is not that dissimilar to writing a procedure in any other language. Although, as we move on, I think you’ll find that the syntax we have to use to get anything done is quite cryptic.