Friday, May 6, 2011

SQLite - query involving 2 tables

Hi,

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.

From stackoverflow
  • 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
    

0 comments:

Post a Comment

Note: Only a member of this blog may post a comment.