Results 1 to 4 of 4

Thread: Problem With SQL Database

  1. #1
    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

  2. #2
    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.

  3. #3
    Join Date
    May 2008
    Posts
    2,012

    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.

  4. #4
    Join Date
    Apr 2008
    Posts
    2,005

    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.

Similar Threads

  1. image database display problem
    By mutago in forum Software Development
    Replies: 1
    Last Post: 03-02-2012, 12:09 AM
  2. SQL problem if tuple is already in the database
    By Macbeth in forum Software Development
    Replies: 4
    Last Post: 17-11-2009, 09:02 PM
  3. Problem while database connection in java
    By Jagriti in forum Software Development
    Replies: 3
    Last Post: 17-11-2009, 11:32 AM
  4. Database relationships problem
    By Barny in forum Software Development
    Replies: 4
    Last Post: 05-01-2009, 09:05 AM
  5. Problem with DATABASE
    By Celaeno in forum Software Development
    Replies: 3
    Last Post: 29-12-2008, 07:33 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,280,169.11738 seconds with 17 queries