Python Forum
Pyhton and SQL Lite3 Data Queries
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Pyhton and SQL Lite3 Data Queries
#1
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!!
Reply
#2
(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
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
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()
Reply
#4
try
SELECT * FROM stock WHERE stock_location LIKE '%Not%' OR stock_location LIKE '%Lost%'
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#5
Works 100% Thank YOU!!!!!!!!!!!!!!!!!!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Vlookup function in Pyhton antozas 1 590 Oct-02-2023, 04:16 AM
Last Post: vikraman
  Too many queries? lorasf 6 918 Jul-04-2023, 04:27 AM
Last Post: lorasf
  Reading Multiple text Files in pyhton Fatim 1 1,885 Jun-25-2021, 01:37 PM
Last Post: deanhystad
  Text File Manipulation Queries? JustJeff 2 2,077 Apr-10-2021, 08:12 PM
Last Post: JustJeff
  Pyhton code help from head first with python Shaikat_99 3 3,084 Jun-07-2020, 09:12 AM
Last Post: snippsat
  start interactive pyhton shell with pre-loaded custom modules Viktor 2 2,140 Apr-09-2020, 08:25 AM
Last Post: Viktor
  PYHTON not opening files profficial 11 13,350 Feb-15-2020, 09:06 AM
Last Post: bharathendra
  Basic Pyhton for Rhino 6 question about variables SaeedSH 1 2,107 Jan-28-2020, 04:33 AM
Last Post: Larz60+
  Pyhton Coding Help Needed (very small error) friduk 2 2,402 Oct-23-2019, 08:41 AM
Last Post: Gribouillis
  2 queries how to use "row" zxcv 1 1,914 Oct-30-2018, 04:19 AM
Last Post: nilamo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020