Python Forum

Full Version: Multi Select from SQL
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi Gurus,
I am planning to get multiple values from single select from Database and use it in the code further down as per the need of the project.
I am trying like this

FeedId[] = Select column1, column2, column3 from MyTable

Id=FeedId[0]
BatchId=FeedId[1]
MyLoc=Feedid[2]

but this is not working. could you please share how to get these multiple values get extracted.
I'd suggest using SqlAlchemy, tutorial here: SQLAlchemy Tutorial
It is much easier to use once setup.
Hi Larz,
I need in this format when we have a single record and do not need loop

Local_id = pd.read_sql_query('select ISNULL(max(Id),0)+1 from firstTable', conn)
Local_id
# =============================================================================
# Now Select One value from the DB to local variable
# and setting up few columns those are not from Data File
# =============================================================================
oLid=Local_id.loc[0]
oLid
anyone?
Hi Experts. need your help
Hi Experts,
can anyone help me here?
(Oct-13-2020, 10:29 AM)tehzeebahmed Wrote: [ -> ]Local_id = pd.read_sql_query('select ISNULL(max(Id),0)+1 from firstTable', conn)
Local_id
# =============================================================================
# Now Select One value from the DB to local variable
# and setting up few columns those are not from Data File
# =============================================================================
oLid=Local_id.loc[0]
oLid
But what is your question? Does it work? Does it not give the right result? Do you get an error message? What does table "firstTAble" look like?
Is the database really huge? What happened if you try to retrieve all elements, e.g. pd.read_sql_query('select * from your_db')... It is hard to answer questions dealing with external resources... How can we reproduce the problem?!