Skip to content

Instantly share code, notes, and snippets.

@amadoru
Created December 1, 2012 14:23
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amadoru/4182564 to your computer and use it in GitHub Desktop.
Save amadoru/4182564 to your computer and use it in GitHub Desktop.
Synonyms for Dulith
Disclaimer: I have not run these queries against any database and the syntax is in pure SQL so adjust as it fits and ignore typos
Create a table like this.
CREATE TABLE words (
id INT PRIMARY KEY NOT NULL AUTO_INCREMENT,
group INT NOT NULL,
word VARCHAR(100) NOT NULL,
);
And then insert the values. Group synonyms together and assign them the same group id.
INSERT INTO words(group, word) VALUES (1, "hello");
INSERT INTO words(group, word) VALUES (1, "hi");
INSERT INTO words(group, word) VALUES (1, "hey");
INSERT INTO words(group, word) VALUES (2, "afraid");
INSERT INTO words(group, word) VALUES (2, "scared");
Query like this.
SELECT word
FROM words
WHERE group = (
SELECT group
FROM words
WHERE word = "hello");
Tada!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment