Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 26-03-2009
Member
 
Join Date: Jan 2009
Posts: 69
Problem With SQL Database

I am not a good programmer in sql programming language. I am creating a program in sql database in order to display a table consisting of two columns.

The requirement for the query code is:
Select Desc,Name from tablename ORDER BY Desc.
I want to display only the Desc data in the UI.
But in case if the Desc is having a null,I will show the "Name" in the UI.

Please suggest some solution regarding this
Reply With Quote
  #2  
Old 26-03-2009
Member
 
Join Date: Apr 2008
Posts: 1,948
Re: Problem With SQL Database

The syntax for an ORDER BY statement is as follows:

SELECT "column_name"
FROM "table_name"
[WHERE "condition"]
ORDER BY "column_name" [ASC, DESC]

The [] means that the WHERE statement is optional. However, if a WHERE clause exists, it comes before the ORDER BY clause. ASC means that the results will be shown in ascending order, and DESC means that the results will be shown in descending order. If neither is specified, the default is ASC.

It is possible to order by more than one column. In this case, the ORDER BY clause above becomes

ORDER BY "column_name1" [ASC, DESC], "column_name2" [ASC, DESC]

Assuming that we choose ascending order for both columns, the output will be ordered in ascending order according to column 1. If there is a tie for the value of column 1, we then sort in ascending order by column 2.
Reply With Quote
  #3  
Old 26-03-2009
Member
 
Join Date: May 2008
Posts: 2,008
Re: Problem With SQL Database

When ORDER BY is used in the definition of a view, inline function, derived table, or subquery, the clause is used only to determine the rows returned by the TOP clause. The ORDER BY clause does not guarantee ordered results when these constructs are queried, unless ORDER BY is also specified in the query itself.
Reply With Quote
  #4  
Old 26-03-2009
Member
 
Join Date: Apr 2008
Posts: 2,001
Re: Problem With SQL Database

SELECT ProductID, Name FROM Production.Product
WHERE Name LIKE 'Lock Washer%'
ORDER BY ProductID DESC;

order_by_expression

Specifies a column on which to sort. A sort column can be specified as a name or column alias, or a nonnegative integer representing the position of the name or alias in the select list. An integer cannot be specified when the order_by_expression appears in a ranking function. A sort column can include an expression, but when the database is in SQL Server (90) compatibility mode, the expression cannot resolve to a constant. Column names and aliases can be qualified by the table or view name. In SQL Server, qualified column names and aliases are resolved to columns listed in the FROM clause. If order_by_expression is not qualified, the value must be unique among all columns listed in the SELECT statement.

Multiple sort columns can be specified. The sequence of the sort columns in the ORDER BY clause defines the organization of the sorted result set.

The ORDER BY clause can include items that do not appear in the select list. However, if SELECT DISTINCT is specified, or if the statement contains a GROUP BY clause, or if the SELECT statement contains a UNION operator, the sort columns must appear in the select list.

Additionally, when the SELECT statement includes a UNION operator, the column names or column aliases must be those specified in the first select list.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Problem With SQL Database"
Thread Thread Starter Forum Replies Last Post
image database display problem mutago Software Development 1 03-02-2012 12:09 AM
SQL problem if tuple is already in the database Macbeth Software Development 4 17-11-2009 09:02 PM
Problem while database connection in java Jagriti Software Development 3 17-11-2009 11:32 AM
Database relationships problem Barny Software Development 4 05-01-2009 09:05 AM
Problem with DATABASE Celaeno Software Development 3 29-12-2008 07:33 PM


All times are GMT +5.5. The time now is 03:20 PM.