Skip to content
wade.one

wade.one

wade womersley – york based software engineer

  • Home
  • 2010
  • February
  • 26
  • #PHPUK2010 Part 2 (MySQL stuff)

#PHPUK2010 Part 2 (MySQL stuff)

Posted on February 26, 2010 By Wade No Comments on #PHPUK2010 Part 2 (MySQL stuff)
Programming

Just picked up a nice tid-bit on creating a unique index on a two column table where the values in each column may be either way around but you only ever want one instance of the value in that row. So what this means is, inserting 2,1 and 1,2 for example would result in only the first of the two inserts succeeding.

CREATE UNIQUE INDEX ON tablename (LEAST(col1,col2), GREATEST(col1,col2));

Also, WITH, I’ll be honest, never thought about using it to create temporary views. This is a bad example but shows the structure rather well:

WITH tempView (a,b) AS (
SELECT table1.col1, table2.col2
FROM table1
LEFT JOIN table2
ON table1.id=table2.id
)
SELECT a,b FROM tempView;

Better yet is changing this to WITH RECURSIVE tempView and then adding in a select inside the WITH that recalls tempView. The great example he gave is for getting flights from A to B with a varying  amount of stops, it would be possible to get all routes from A to B with one MySQL query, as long as the data stored all connecting routes.

Incidentally, while there is some great stuff coming out of this RDBMS talk, I think the queries are really hurting a lot of people’s heads. Good stuff though.

Share:

  • Click to share on Facebook (Opens in new window) Facebook
  • Click to share on X (Opens in new window) X
  • Click to share on Tumblr (Opens in new window) Tumblr
  • Click to share on Pinterest (Opens in new window) Pinterest
  • Click to share on LinkedIn (Opens in new window) LinkedIn
  • Click to share on Reddit (Opens in new window) Reddit

Related

Comments

comments

Tags: PHP Conference 2010

Post navigation

❮ Previous Post: #PHPUK2010 Part 1
Next Post: Regex-fu #PHPUK2010 ❯

You may also like

Programming
PHPNW09 – PHP North-West 09 Conference
October 10, 2009
Programming
MySQL – Binary(16) and scalability
January 29, 2010
Programming
Adobe Browser Labs – Better than Microsoft Expression
October 28, 2009
Gaming
Epic Games releases Unreal Development Toolkit for FREE
November 7, 2009

Leave a Reply Cancel reply

You must be logged in to post a comment.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

  • AI
  • artificial intelligence
  • Ego-centric
  • Events
  • Films
  • Food
  • Gaming
  • Gym
  • Hardware
  • Holidays
  • News
  • PHP
  • Programming
  • Random Stuff
  • Reviews
  • Science
  • SEO
  • Software
  • Software Engineer
  • Support
  • Uncategorized
  • Work

Copyright © 2025 wade.one.

Theme: Oceanly News Dark by ScriptsTown