mardi 28 juillet 2015

SQLITE-How to select only the rows that have a column with a repeated value?

So, i am building an Android app for a bus schedule between my village and Barcelona.

I have built an Sqlite database as follows (probably it's a really bad design, but i'm a newbie in databases):

run | stopCode | time

1.........1.......620

1.........2.......650
.

.

.

.

5........11.......NULL

5........12.......1020

And so on.

Now, i use the following SQL statement in order to pick the rows that match my criteria:

 SELECT run,stopCode,time FROM tablename WHERE time> x AND time <>'' AND(stopCode=1 or stopCode=8);

Using this sentence gives me an output similar to this:

6(run)|8(stopCode)|1045(time)

9|1|1900

9|8|2000

Now, my problem is that i want to select ONLY the rows that have the run value repeated twice, if it only appears once it means that the bus has a NULL destination in that particular run.

I tried using COUNT(*) c, blabla c=2, but that gives me only the second row with the repeated run number, and i want to select both of them (which would correspond to where u pick the bus and where u wanna go down). Any clues how to do it?

Thanks Guys, and sorry for any eyebleeding i may have caused in my horrible database design.

Aucun commentaire:

Enregistrer un commentaire