sql break select if condition is false after multiply successfully results in a raw
I have an ordered dictionary in SQL database that looks like
word meaning word1 meaning1_word1 word1 meaning2_word1 word2 meaning1_word2
I want to select all word1 and then terminate the select statement
and it's should looks like this:
SELECT * FROM dictionary WHERE word = "word1" WHILE (word = "word1")
P.S. solution should work with SQLite or Postgres
It maybe worth ordering by the word and then adding onto the where clause to be below or equal to the word being looked up....
SELECT * FROM dictionary WHERE word = 'word1' AND word <= 'word1' ORDER by word
First, you should be writing the query as:
SELECT d.* FROM dictionary d. WHERE d.word = 'word1';
If you want the first match, then add
fetch first 1 row only.
If you want performance, add an index on
create index idx_dictionary_word on dictionary(word);
This will speed the query -- assuming the constant and the word have the same (or compatible) collations.