Python Forum
Pyhton and SQL Lite3 Data Queries - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Pyhton and SQL Lite3 Data Queries (/thread-12958.html)



Pyhton and SQL Lite3 Data Queries - compumarsh - Sep-20-2018

Guys, I am new to Python and would like to ask for assistance.
I am busy with a database using forms.
One of the things I have is a button on the form, basically giving me data in a table specified by a specific word.
The code for this is :
 cursor.execute("SELECT * FROM `stock` WHERE `stock_location` LIKE '%Not%'") 
Works fine, gives me the data I want, problem is I want another word inclujded in the data output.
I read online and tried all the examples, nothing works, either I get a blank sheet back or the same "single" specified word data as it normally will and or an error.
I tried the example code as I gave it here and added the AND and the OR many different ways but still no luck, please assist!!


RE: Pyhton and SQL Lite3 Data Queries - buran - Sep-20-2018

(Sep-20-2018, 02:07 PM)compumarsh Wrote: Works fine, gives me the data I want, problem is I want another word inclujded in the data output
what does it mean another word included in the data? give an example. also post what have you tried


RE: Pyhton and SQL Lite3 Data Queries - compumarsh - Sep-20-2018

Hi, Thx for the reply. Basically I pull data from a table containing many phrases, for example....NOT in Stock.....In for Repairs....Handled.....Completed.
I basically only want the data containing the words......Not in Stock.....and then also.......Lost.
So I want the code to send me back the data in my form with only sentences which include the words...Lost and Not.
As per my code it works fine as I get the data from the one word specified in the code which is...not.
I n ow want to add another words so I get both back in one sheet.
I tried a few things already : This is the original Code that works for the one word : cursor.execute("SELECT * FROM stock WHERE stock_location LIKE '%Not%'")

I have tried SELECT * FROM stock WHERE stock_location LIKE '%Not%' AND '%Lost%'"
also : SELECT * FROM stock WHERE stock_location LIKE '%Not%' OR WHERE stock_location LIKE '%Lost%'"
and I tried : SELECT * FROM stock WHERE stock_location LIKE '%Not%', '%Lost%'

Fairly new to it all but here is also a complete section of what it looks like, as stated it works but only for the one word.

def Listmissing():
        Database()
        cursor.execute("SELECT * FROM `stock` WHERE `stock_location` LIKE '%Not%'")
        tree.delete(*tree.get_children())
        fetch = cursor.fetchall()
        for data in fetch:
            tree.insert('', 'end', values=(data))
        cursor.close()
        conn.close()



RE: Pyhton and SQL Lite3 Data Queries - buran - Sep-20-2018

try
SELECT * FROM stock WHERE stock_location LIKE '%Not%' OR stock_location LIKE '%Lost%'



RE: Pyhton and SQL Lite3 Data Queries - compumarsh - Sep-21-2018

Works 100% Thank YOU!!!!!!!!!!!!!!!!!!