Skip to main content
added 136 characters in body
Source Link
Tauseef Hussain
  • 1.1k
  • 4
  • 17
  • 29
from sqlalchemy import create_engine
engine = create_engine('mssql+pymssql://myusername:[email protected]:1433/AQOA_Core')
connection = engine.connect()
result = connection.execute("""SELECT DISTINCT Distributor FROM Product""")
for row in result:
    print row[0]
connection.close()

The above code returns a result set as:

FRANCETV
GAUMONT
M6SND
PATHE
STUDIOCANAL
TF1
WARNER

What if I want to print just one value without changing the query?

Tried print row[0][1], print row[0:1] This was tried to print just the first value FRANCETV

Basically I want to be able to print each one of the values in the result set seperately without making changes to the query.

connection = engine.connect()
result = connection.execute("""SELECT DISTINCT Distributor FROM Product""")
for row in result:
    print row[0]
connection.close()

The above code returns a result set as:

FRANCETV
GAUMONT
M6SND
PATHE
STUDIOCANAL
TF1
WARNER

What if I want to print just one value without changing the query?

Tried print row[0][1], print row[0:1] This was tried to print just the first value FRANCETV

Basically I want to be able to print each one of the values in the result set seperately without making changes to the query.

from sqlalchemy import create_engine
engine = create_engine('mssql+pymssql://myusername:[email protected]:1433/AQOA_Core')
connection = engine.connect()
result = connection.execute("""SELECT DISTINCT Distributor FROM Product""")
for row in result:
    print row[0]
connection.close()

The above code returns a result set as:

FRANCETV
GAUMONT
M6SND
PATHE
STUDIOCANAL
TF1
WARNER

What if I want to print just one value without changing the query?

Tried print row[0][1], print row[0:1] This was tried to print just the first value FRANCETV

Basically I want to be able to print each one of the values in the result set seperately without making changes to the query.

Source Link
Tauseef Hussain
  • 1.1k
  • 4
  • 17
  • 29

Python: Print only one value of an SQL query result set

connection = engine.connect()
result = connection.execute("""SELECT DISTINCT Distributor FROM Product""")
for row in result:
    print row[0]
connection.close()

The above code returns a result set as:

FRANCETV
GAUMONT
M6SND
PATHE
STUDIOCANAL
TF1
WARNER

What if I want to print just one value without changing the query?

Tried print row[0][1], print row[0:1] This was tried to print just the first value FRANCETV

Basically I want to be able to print each one of the values in the result set seperately without making changes to the query.