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 7420111
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T08:10:58+00:00 2026-05-29T08:10:58+00:00

I write a query and give a table in output but I want to

  • 0

I write a query and give a table in output but I want to every row of my table has a number automatically that starts from 1. for example , I want that my table has “number” column that first row of my table have 1 in that column , second row of my table have 2 in that column , third row of my table have 3 in that column , …
How can I do this ?
thanks

** My DBMS is MySQL **

  • 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-29T08:10:58+00:00Added an answer on May 29, 2026 at 8:10 am

    Use a variable and increment it like following.

    set @num:=0; 
    select *,  @num:=@num+1 `Row` from names;
    

    Example

    mysql> create table names( name varchar(10) primary key )engine=Innodb charset=utf8 collate utf8_general_ci;
    Query OK, 0 rows affected (0.09 sec)
    
    mysql> insert into names values('a'), ('b'), ('cat'), ('dog'), ('parrot'), ('bird');
    Query OK, 6 rows affected (0.04 sec)
    Records: 6  Duplicates: 0  Warnings: 0
    
    mysql> set @num:=0; select *,  @num:=@num+1 `Row` from names;
    Query OK, 0 rows affected (0.00 sec)
    
    +--------+------+
    | name   | Row  |
    +--------+------+
    | a      |    1 |
    | b      |    2 |
    | bird   |    3 |
    | cat    |    4 |
    | dog    |    5 |
    | parrot |    6 |
    +--------+------+
    6 rows in set (0.00 sec)
    

    Note: If you use * make sure it precedes.

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

Sidebar

Related Questions

How do I write a query that outputs the row number as a column?
I want to write a query to select from a table all rows with
I want to write a query that will match up a string from one
I want to write a query like this: SELECT o.OrderId, MAX(o.NegotiatedPrice, o.SuggestedPrice) FROM Order
I need to write a query that will group a large number of records
I have a table that has some columns: User, Category, Value And I want
I am trying to query a table that has dates in it. I would
During my work with databases I noticed that I write query strings and in
i want to write a query with Full-Text-Search on a column with varbinary(max) type
I need to write a query that returns all object less that or equal

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.