0

For example, if I store 150 phone numbers in the table phone_numbers. How will I go about retrieving the row number containing 555-555-5555? I checked out many different queries, but seems I have to loop through all the data to find it.

2
  • 1
    Possible duplicate of sqlite get ROWID Jul 3, 2017 at 23:06
  • Although I offered an answer below, on re-reading the question, I think I may have misunderstood what you are asking. What exactly do you mean by "row number" and how is it going to be used? Keep in mind that relational database tables are conceptually sets, not arrays.
    – varro
    Jul 5, 2017 at 16:22

2 Answers 2

0

Use the ROW_NUMBER() function ... use the sql API definition to know more about the function

Good luck

EDIT:

Example you have a table called 'testTable', and column called 'testId' and a column called 'testName'

SELECT testId , tesName, (
     SELECT COUNT(*) FROM testTable AS a
            WHERE a.testName <= b.Name) AS row_Num
           FROM testTable AS b
     ORDER BY testName, testId;

I hope I'm right this time

thanks and let me know please if it works or not I'm trying my best

2
  • SQLite does not support row number AFAIK. Jul 4, 2017 at 1:32
  • Update answer please check answer now =) and sorry did not notice your are asking sqlite @Weakman10122
    – Abdullah
    Jul 4, 2017 at 2:24
0

Try:

SELECT rowid FROM phone_numbers WHERE number ='555-555-5555';
1
  • Thank you for this code snippet, which may provide some immediate help. A proper explanation would greatly improve its educational value by showing why this is a good solution to the problem, and would make it more useful to future readers with similar, but not identical, questions. Please edit your answer to add explanation, and give an indication of what limitations and assumptions apply.
    – basvk
    Jul 5, 2017 at 5:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.