SQLite - complex queries -


I get a random row from my table using the following query:

  SELECT Value_id FROM Table 1 by Random () range 1  

I have 3 tables: Table 1 and Table 2 - There are tables that have a line ID and its value is I Table 3 and The column 3 of the rows in column 2 also has the table 3.

ie:

  Table 1: 1 - Canada 2 - USA 3 - UK 4 - France 5 - Africa 6 - China Table 2: 1 - New York 2 - Vancouver 3 - Paris 4 - London 5 - Ottawa 6 - Los Angeles Table 3: (without table 3 queued) 1 - 2 1 - 5 2 - 1 2 - 6 3 - 4 4 - 3  

So from Table 3 I can say that New York is a city in the United States, and so on. And at the same time, I can have undefined value in Table 3. (For example, they are Africa and China, so I do not want to get them in any result)

What do I have to do, get Table 1 from random ID, but only in Table 3 Has been defined. In this particular case, I do not want to get 5 and 6 as a result.

How can I write my query to achieve my goal?

Thanks in advance.

Edit: The problem is that when I'm trying to get a line that is not defined in table 3, then the app cross. It is not zero, as I wrote earlier, it is not present in Table 3. How can I rewrite the query to properly manage my case?

You did not tell us how to name table3 in fields , But with a clear meaning for example they are named tab1_id and tab2_id , try:

  SELECT table1.value_id FROM Table1 INNER Table 1 Go to Table 1 1.value_id = Table 3 TAB1_ID WHERE table3.tab2_id Random () range 1)  

Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -