I don't know python, but because you have count(*) and no group by, it will only return one row, with the total rows that matched your where clause. The Item1, Item2, Item3 are arbitrary values that were in the two rows of your data.

You can either remove the count(*) and get both rows, or as someone else said, add a group by and get a row for each distinct values of Items 1-3.

David

On 05/12/2012 05:24 AM, philherna wrote:
Hi,


I am using sqlite commands in my python script to output data from a sqlite
database. My problem is however a Sqlite coding one.

I can open, and select simple elements from the database easily but I have
trouble for one specific issue.
For example, to select the content of the rows Item1 , Item2 and Item3 for
which Item55 is equal to 888, I type:

query = "select Item1,Item2,Item3, count(*) from %s where Item55 in (%s)" %
(Database,888)
c.execute(query)
results = c.fetchone()

If I type in Python:
print results    # I get a the unique object which satisfies Item55=888.
(0.2, 0.5, 0.9, 1)
in which the 3 first elements are the values for Item1 , Item2 and Item3,
and the last element tells me that I have done "oneobject matching the
query", i.e. the selected columns for which Item55=888.
However, i am not quite sure that I really well understand why I am returned
this last element...

And for instance,
print results[1] # gives
0.5 # as expected

Now, if I want to select to more objects contained in an array, I can do:
Array = [888,999]
query = "select Item1,Item2,Item3, count(*) from %s where Item55 in (%s)" %
(Database,Array)
c.execute(query)
results = c.fetchall()

The fetchall command is supposed to return all the rows, as far as I
understand Sqlite... My problem is that i don't understand the query results
in this case. Indeed,
print results # gives
(0.2, 0.5, 0.9, 2)
in which the last element tells me (again, as far as I understand ...) that
I have submitted "2 queries", i.e. selected rows for which Item55=888 and
999. I would have expected a result to be a matrix with 2 rows, not a 1D
array...
print results[1][0] # gives
IndexError: list index out of range


Does anyone has an idea of what I am doing wrong here?
Thanks in advance !

_______________________________________________
sqlite-users mailing list
[email protected]
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to