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

  • Home
  • SEARCH
  • 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 7722055
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T04:04:48+00:00 2026-06-01T04:04:48+00:00

Is it possible to return the row number as an ID? In my view

  • 0

Is it possible to return the row number as an ID?
In my view where i merge my tables I can’t make a unique ID because I need to create left
joins to store every value:

CREATE VIEW
sphinx
AS
SELECT

company.company_id,
company.company_name,
company.company_keywords,

company_address.address_street,
company_address.address_number,
company_address.address_telephone,
company_address.address_fax,
company_address.address_email,
company_address.address_website,
company_address.address_authorized,

company_contact.contact_name,
company_contact.contact_surname,
company_contact.contact_telephone,
company_contact.contact_mobilephone,
company_contact.contact_fax,
company_contact.contact_email,

company_page.page_content,
company_page.page_description,
company_page.page_keywords

FROM company
LEFT JOIN company_address ON company.company_id = company_address.company_id
LEFT JOIN company_page ON company.company_id = company_page.company_id
LEFT JOIN company_contact ON company.company_id = company_contact.company_id

When I receive the row number i can just do SELECT * FROM sphinx LIMIT 1 OFFSET rowNumber
to get the information of that row.

Thanks for your time.

  • 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-06-01T04:04:50+00:00Added an answer on June 1, 2026 at 4:04 am

    You can do it the following way

    SELECT * FROM
    (
    SELECT 
    (@rownum:=@rownum + 1) as rownumber, q.*
    FROM (
    SELECT
    * /*shortened for readability*/
    FROM company
    LEFT JOIN company_address ON company.company_id = company_address.company_id
    LEFT JOIN company_page ON company.company_id = company_page.company_id
    LEFT JOIN company_contact ON company.company_id = company_contact.company_id
    , (select @rownum:=0) r
    ) q
    ) asdf
    WHERE rownumber BETWEEN 2 AND 3 /*or whatever*/
    

    EDIT: To explain a bit more:

    This one

    , (select @rownum:=0) r
    

    declares and initializes the variable which will serve as our rownumber.
    If you would include @rownum in the SELECT list of your inner most query, you would get a column which has the value 0 in each row.

    So you make this inner query a subquery and just add 1 to the @rownum variable.
    With only this

    SELECT 
    (@rownum:=@rownum + 1) as rownumber, q.*
    FROM (
    SELECT
    * /*shortened for readability*/
    FROM company
    LEFT JOIN company_address ON company.company_id = company_address.company_id
    LEFT JOIN company_page ON company.company_id = company_page.company_id
    LEFT JOIN company_contact ON company.company_id = company_contact.company_id
    , (select @rownum:=0) r
    ) q
    

    you would already have a rownumber. Since you can’t refer to the column alias rownumber in the WHERE clause, you would have to write something like

    WHERE (@rownum:=@rownum + 1) BETWEEN 2 AND 3 /*or whatever*/
    

    but this would lead to false results, because the @rownum variable would get incremented again and your rownumber would be like

    2
    4
    6
    

    and so on. Therefore you have to put it in another subquery and then you can “limit” your query via the WHERE clause.

    Any more questions?

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

Sidebar

Related Questions

In Oracle, it's possible to do a SELECT statement that returns the row number
The documentation for ref() mentions several possible return values. I understand most of them,
Possible Duplicate: Return value from thread I want to get the free memory of
Is it possible to return a 307 Temporary Redirect from a controller in ASP.NET
Is it possible to return a list of all the properties implemented by an
Is it possible to return a HashMap to R with the rJava extension of
Is it possible to return a single value and an enumerable collection using LINQ
Since it's really not possible to return a single embedded document (yet), what is
In Kohana V3 is it possible to return result set as an array() or
i am wondering if it is possible to return multiple objects with a JSON

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.