Wednesday, October 29, 2008

Tuesday, October 28, 2008

SQL: DISTINCT and SUM using one SELECT Statement

When you do this, you'll have an error like this:

Msg 8120, Level 16, State 1, Line 1
Column 'table1.column1' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.

so simply put columns in the GROUP BY clause and it will work fine:

SELECT distinct(column1), column2, SUM(column3)/3 FROM table1 WHERE column2 = something GROUP BY column1, column2

SQL: INSERT multiple records using one INSERT Statement

What would you do if you want to insert whole table or a whole result from a SELECT statement using only a single line of INSERT statement?

Usually a DB Admin will do this in a copy-paste manner:

INSERT INTO Table1 (Column1, Column2) VALUES ('First' , 1);
INSERT INTO Table1 (Column1, Column2) VALUES ('Second' , 2);

This is the solution:

INSERT INTO Table1 (Column1, Column2) SELECT Column1, Column2 FROM Table2 WHERE Column1 = something;

And to insert complicated results from different tables, use UNION ALL:

INSERT INTO Table1 (Column1, Column2)
SELECT 'First' , 1
UNION ALL
SELECT 'Second' , 2
UNION ALL
SELECT 'Third' , 3
UNION ALL
SELECT 'Fourth' , 4
UNION ALL
SELECT 'Fifth' , 5;

Monday, October 20, 2008

Who is Paris Hilton's latest fantasy?


She's holding a copy of our video scandal...

Why so serious? Let's put a smile on that face...

The "Dark knight" may be the greatest Batman ever. I am a Batman fanatic and have watched every single Batman movie and animated series but I've never seen a story so realistic and created in modern times as good as this one. Besides its great action, suspense, and special effects, the movie highlighted the drama within. It captured the being of every character and reasons for every action.

I've read so many outstanding ratings and comments for this movie especially for the performance of the late Heath Ledger as Joker. I myself am stunned on the awesome portrayal of the Joker. Heath excellently captured the scary image of Joker with sense of humor. The over-all image was great, the make-up, hair, costume, posture, voice, laugh, accent, and ofcourse the acting. In this movie, the Batman was not the star but the Joker and Harvey Dent (two-face). Heath deserves an Oscar for this one.

I always buy a shirt for the hero fad. This time, I bought the purple Joker.

Wednesday, October 15, 2008

Nona passed away...

Hi everyone,

Everybody knows what happened already but for the benefit of those who are not aware, especially those who are out of the country, Ate Nona passed away at 11:14 last night.

I was shocked when Belle forwarded me Anthony's text message at 5:30 am. Di na ako nakatulog afterwards. I didn't know that Nona was confined for 3 weeks already.

It was indeed a very very sad news to us because Nona is one of the kindest, if not the kindest person in PCHRD. She's one of our RICUP family, and one of our Herdin team. She as a pioneer of the project, I can proudly say that Nona = Herdin. And if there's someone who will truly miss her and will be affected of her loss at the office, that would be Ate Belle.

I agree with Vince, Nona is a strong woman. We must admire that. I am truly happy I had the chance to have a heart-to-heart one-on-one talk with her regarding work, life, and her disease before I left pchrd, and before she left us.

My deepest condolence to her family, Anthony and their two kids.

We love you Nona, Farewell... We'll miss you but you'll always be in our hearts...