-1

I want to fetch the last row element of my table to my homepage,where my table is updated daily from backend. I am using the query for now is :

select COLUMN_NAME from TABLE_NAME order by COLUMN_NAME desc limit 1;

which is not fetching the values properly. this query does not able to fetch values like : ********* and even not working properly. I want a query which can fetch all the type of values which is present in the last row of my table.

Barbaros Özhan
  • 59,113
  • 10
  • 31
  • 55
Shivam sharma
  • 97
  • 1
  • 1
  • 3
  • If you want to fetch all the columns, use `SELECT *` – Barmar May 16 '20 at 09:43
  • 1
    If that's not the solution, you haven't described the problem. Tables don't have a "last row", ordering is only based on a criteria you specify in the query. – Barmar May 16 '20 at 09:44
  • solution to similar question: https://stackoverflow.com/questions/5191503/how-to-select-the-last-record-of-a-table-in-sql – SidPro May 16 '20 at 09:46
  • Your question needs sample data, desired results, and a clear explanation of what you mean by "last row element". – Gordon Linoff May 16 '20 at 11:44

1 Answers1

0

In MsSQL you must use Top 1:

SELECT TOP 1 `ColumnName` FROM `tableName` ORDER BY `ID` DESC

While in MySQL the one you mentioned is correct if the second COLUMN_NAME pointing to id

SELECT `name` FROM `tableName` ORDER BY `id` DESC LIMIT 1;
Hussein Akar
  • 425
  • 3
  • 12