SQL Listing all column names alphabetically
Yes, and no :-)
SQL itself doesn't care what order the columns come out in but, if you were to use:
select age, name, sex from ...
you'd find that they probably came out in that order (though I'm not sure SQL standards mandate this).
Now you may not want to do that but sometimes life isn't fair :-)
You also have the other possibility of using the DBMS data definition tables to dynamically construct a query. This is non-portable but most DBMS' supply these table (such as DB/2's SYSIBM.SYSCOLUMNS
) and you can select the column names from there in an ordered fashion. Something like:
select column_name from sysibm.syscolumns
where owner = 'pax' and table_name = 'movies'
order by column_name;
Then you use the results of that query to construct the real query:
query1 = "select column_name from sysibm.syscolumns" +
" where owner = 'pax' and table_name = 'movies'" +
" order by column_name"
rs = exec(query1)
query2 = "select"
sep = " "
foreach colm in rs:
query2 += sep + colm["column_name"]
sep = ", "
query2 += " from movies order by rating"
rs = exec(query2)
// Now you have the rs recordset with sorted columns.
However, you really should critically examine all queries that select *
- in the vast majority of cases, it's unnecessary and inefficient. And presentation of the data is something that should probably be done by the presentation layer, not the DBMS itself - the DBMS should be left to return the data in as efficient a manner as possible.
Sort Column names alphabetically in a table
You may get the List of Column from the System View which is INFORMATION_SCHEMA.COLUMNS
. You can do a Select on the View and Filter by Table there order the List based on any of your desired values as mentioned below:
SELECT
*
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME ='YourTableName'
ORDER BY COLUMN_NAME ASC
mysql get table column names in alphabetical order
The ANSI INFORMATION_SCHEMA tables (in this case, INFORMATION_SCHEMA.COLUMNS) provide more flexibility in MySQL:
SELECT c.column_name
FROM INFORMATION_SCHEMA.COLUMNS c
WHERE c.table_name = 'tbl_name'
-- AND c.table_schema = 'db_name'
ORDER BY c.column_name
How to get a by alphabetical order in the select column of sql query?
You require an ORDER BY clause at the end of your SQL query, to order the resultset by the column containing the brand name...
select * from zhaq_woocommerce_attribute_taxonomies where
attribute_name='brand' ORDER BY {column_to_order_by}
...simply replace {column_to_order_by} with the column name.
How to order by column name when getting a list of columns their data types using DESCRIBE in SQL Developer?
You can't change the way the result of a DESCRIBE command are displayed, but you could query the system catalog directly:
select column_name, data_type, column_id
from user_tab_columns
where table_name = 'YOUR_TABLE'
order by column_name
If the current user does not own the table you are looking at, use all_tab_columns
but you have to provide the owner name as well:
select column_name, data_type, column_id
from all_tab_columns
where table_name = 'YOUR_TABLE'
and owner = 'SOME_USER'
order by column_name
sql query to retrieve only those columns names starting with some alphabet
This sample query:
SELECT COLUMN_NAME
FROM Database.INFORMATION_SCHEMA.COLUMNS
WHERE COLUMN_NAME LIKE '%st1%'
Or
SELECT COLUMN_NAME
FROM INDUS2_RF.INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = N'main_rf_analog' And COLUMN_NAME LIKE '%st1%'
check this from more info. https://msdn.microsoft.com/en-us/library/aa933204%28SQL.80%29.aspx
How do you return the column names of a table?
Not sure if there is an easier way in 2008 version.
USE [Database Name]
SELECT COLUMN_NAME,*
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = 'YourTableName' AND TABLE_SCHEMA='YourSchemaName'
INFORMATION_SCHEMA.COLUMNS sorted alphabetically initially, then a few days later sorted by ORDINAL_POSITION
In SQL order is not an inherent property of a data set. The wording that appears in the SQL-92 spec is
If an <order by clause> is not specified, then the ordering of the rows ... is implementation-dependent.
You'll find that in some form in a number of places.
There's no server-wide or database-wide option to set it. You need to specify the required order in your query. Your example above becomes
SELECT * from INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = <your table name> order by ORDINAL_POSITION;
You'll need to update your queries.
Sort SQL results by column titles?
- You can construct select query manually.
In Oracle you can obtain columns in alphabetical order like that:
select T.COLUMN_NAME
from all_tab_columns t
where T.TABLE_NAME = ? and T.OWNER= ? order by 1
- I think MULTISET operator is what you need. It relates to collections, but I doubt it can be done in 8i.
Anyway, mb this link will help Oracle Doc
Related Topics
Row_Number() Over Not Fast Enough with Large Result Set, Any Good Solution
SQL Question: Does the Order of the Where Clause Make a Difference
Update Query If Statement for Oracle
Oracle Insert Failure:Not a Valid Month
Product with Multiple Category Type Database Schema
Insert Manually into a Table by SQL Statement, But Key Is Autoincremented
Does Size of a Varchar Column Matter When Used in Queries
Mssql: Update Statement Avoiding the Check Constraint
How to Concatenate Multiple Rows
SQL Server Select Column by Number
Logging Erroneous Queries Only on SQL Server
Get the Number of Affected Rows in a MySQL Update Statement
Postgresql Update Multiple Tables in Single Query
Identity_Insert Is Already on for Table 'X'. Cannot Perform Set Operation for Table 'Y'
Creating Sumif Function in SQL Server 2012