CROSS JOIN for fun

My son, who wishes to be known as “Pigeon” for the duration of this blog, was mixing the names of Hogwarts houses over a game of chess* with his brother:

ONE MILLION POINTS TO GRYFFINPUFF!”

So I said, “Hey guys, I’m going to do a nerdy thing with my database skillz and then show you, okay?

Here’s what I did:

CREATE TABLE #names (
 firstpart varchar(20), 
 lastpart varchar(20)
)
INSERT INTO #names (firstpart, lastpart)
VALUES ('Raven', 'Claw'),
('Slyther', 'In'),
('Huffle', 'Puff'),
('GrYffin', 'Dor')
SELECT a.firstpart + b.lastpart
FROM #names a
CROSS JOIN #names b
ORDER BY 1;

And what we get, of course is a complete list of all the possible Hogwarts houses names, if they were mixed and matched:

  • GryffinClaw
  • GryffinDor
  • GryffinIn
  • GryffinPuff
  • HuffleClaw
  • HuffleDor
  • HuffleIn
  • HufflePuff
  • RavenClaw
  • RavenDor
  • RavenIn
  • RavenPuff
  • SlytherClaw
  • SlytherDor
  • SlytherIn
  • SlytherPuff

See there? Who said CROSS JOIN isn’t useful?

-Jen

*So, you know, I’m not the only nerd here.

6 thoughts on “CROSS JOIN for fun

  1. Pingback: Dew Drop - February 20, 2018 (#2668) - Morning Dew

Comments are closed.