简体   繁体   中英

Why does my output on sqlite inner join multiplies?

I have 2 tables..

I will represent the data inn array....

table1 columns are t1_id, t1_value

table2 columns are t2_id, t2_value, t1_id(FK)

  1. table1={{1,data1},{2,data2}};

  2. table2={{1,d1,t1.1},{2,d2,t1.1},{3,d3,t1.2},{4,d4,t1.2}};

i have a query of..

rs = stmt.executeQuery("SELECT t2_value FROM table2 INNER JOIN table1
             ON table2.t1_id=(SELECT t1_id FROM table1 WHERE t1_value='my_value');")

I got the right value i needed but instead of just..

d1
d2

what I got is..

d1
d2
d1
d2

Please help!

Why not try this:

SELECT t2_value FROM table2 INNER JOIN table1 ON table2.t1_id=table1.t1_id WHERE table1.t1_value='my_value '

SELECT table2.t2_value FROM table2
INNER JOIN table1 ON table2.t1_id = table1.t1_id 
WHERE table1.t1_value='my_value'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM