Skip to content

Instantly share code, notes, and snippets.

@tjtate
Created August 22, 2016 15:49
Show Gist options
  • Save tjtate/993a819a26b5b3a0647966a5d2ff275e to your computer and use it in GitHub Desktop.
Save tjtate/993a819a26b5b3a0647966a5d2ff275e to your computer and use it in GitHub Desktop.
Using this Table definition...
CREATE TABLE test (
id INT NOT NULL,
last_name CHAR(30) NOT NULL,
first_name CHAR(30) NOT NULL,
PRIMARY KEY (id),
INDEX name (first_name, last_name)
);
Which query is faster for selecting a user's first name?
SELECT * FROM test WHERE first_name = 'john' AND last_name = 'smith'
SELECT first_name FROM test WHERE last_name = 'smith' AND first_name = 'john'
Is one query more efficient than the other?
SELECT * FROM test WHERE last_name = 'smith' AND first_name = 'john'
SELECT * FROM test WHERE first_name = 'john' AND last_name = 'smith'
Will this query use the "name" index?
SELECT * FROM test WHERE last_name = 'smith'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment