+ 1
How to select last colum only from database?
2 ответов
+ 6
SELECT <last_field_name> FROM <table_name> will do that, though you will need to know the 'last_field_name' to do it, or are you asking for last record from the table? to get the last record use SELECT with either LIMIT or TOP (depending on DBMS), then add sort ordering ORDER BY DESC.
Hth, cmiiw
+ 1
Hmm it's a strange question but... For example in MS SQL you are able to get last column from the table using something like this:
Declare @ColumnName VARCHAR(100)
set @ColumnName=(SELECT TOP 1 COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS where TABLE_SCHEMA='YOUR TABLE SCHEMA' and TABLE_NAME='YOUR TABLE NAME' Order by ORDINAL_POSITION desc)
Declare @sql nvarchar(max)
set @sql='select ' + @ColumnName + ' from YOUR_TABLE_SCHEMA.YOUR_TABLE_NAME'
EXEC sp_sqlexec @sql
but I have no idea why someone could need it.