Ilya Suzdalnitski
Ilya Suzdalnitski

Reputation: 53540

SQLite - query involving 2 tables

I want to choose a row from a certain table and order the results basing on another table.

Here are my tables:

lang1_words:
word_id - word

statuses:
word_id - status

In each table word_id corresponds to a value in another table.

Here is my query:

SELECT statuses.word_id FROM statuses, lang1_words
WHERE statuses.status >= 0
ORDER BY lang1_words.word ASC

But it return more than 1 row of the same word_id and they results are not being sorted alphabetically.

What is the problem with my query and how can I achieve my goal?

Thanks.

Upvotes: 1

Views: 970

Answers (1)

Nadia Alramli
Nadia Alramli

Reputation: 114933

You need to join the two tables, one way of doing it is:

SELECT statuses.word_id FROM
statuses JOIN lang1_words ON statuses.word_id = lang1_words.word_id
WHERE statuses.status >= 0
ORDER BY lang1_words.word ASC

Upvotes: 7

Related Questions