Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6186777
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T01:56:46+00:00 2026-05-24T01:56:46+00:00

So My problem is this, I have a query that uses Mysql User-defined variable

  • 0

So My problem is this, I have a query that uses Mysql User-defined variable like:
@x:=0 SELECT @X:=@X+1 from some_table and this code returns a column from 1-1000.

However, this query doesn’t work if I sent it through mySQLdb in Python.

connection =MySQLdb.Connect(host='xxx',user='xxx',passwd='xxx',db = 'xxx')
cursor = connection.cursor
cursor.execute("""SET @X:=0;SELECT @X:=@X+1 FROM some_table""")
rows = cursor.fetchall()
print rows

It prints a empty tuple.

How can I solve this?

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T01:56:46+00:00Added an answer on May 24, 2026 at 1:56 am

    Try it as two queries.

    If you want it to be one query, the examples in the comments to the MySQL User Variables documentation look like this:

    SELECT @rownum:=@rownum+1 rownum, t.* FROM (SELECT @rownum:=1) r, mytable t;
    

    or

    SELECT if(@a, @a:=@a+1, @a:=1) as rownum
    

    See http://dev.mysql.com/doc/refman/5.1/en/user-variables.html

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I seem to have a problem with this SQL query: SELECT * FROM appts
I have a nHibernate query like this ICriteria query = session.CreateCriteria(typeof(MyResult)) .Add(Expression.Eq(ResultTypeId, myResult.ResultTypeId)) Problem
I have a problem with an SQL query on Postgresql. This select clause is
We have a query that's taking 3 hours to finish. This wasn't a problem
I have problems running a dynamic LIKE statement in my project: this query works
Ok I have this problem that I've never had before, it's really bugging me.
I'm trying to build a MySQL query that uses the rows in a lookup
I have inherited a bit of Java code that uses Hibernate. Some of the
I hope this makes sense. I have a ASP.NET web application that uses Entity
I have a query which uses the GROUP_CONCAT of mysql on an integer field.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.