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.
You can do it the following way
EDIT: To explain a bit more:
This one
declares and initializes the variable which will serve as our rownumber.
If you would include
@rownumin theSELECTlist 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
you would already have a rownumber. Since you can’t refer to the column alias
rownumberin theWHEREclause, you would have to write something likebut this would lead to false results, because the
@rownumvariable would get incremented again and your rownumber would be likeand 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?