order by usage with multiple options [closed] - sql

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 9 years ago.
Improve this question
I have a SQL query where I want to order the database on type, order and category. Can I have query having all these three?
select * from t_person where name=xyz order by type,category,order

try this:
Use "" (double quotes) to escape the reserved keyword order
select * from t_person where name='xyz'
order by type,category,"order"

Use double quote for correct query:
select * from t_person where name='xyz' order by type,category,"order"

Related

syntax error coming while execute the query [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
select count(*) as distinctname from
(select distinct nationalityname from dbo.profile)
Use an alias for your subqueries
select count(*) as distinctname from
(select distinct nationalityname from dbo.profile) alias_name
or make it simpler like this
select count(distinct nationalityname) from dbo.profile
Just give alias to sub-query
select count(*) as distinctname
from (select distinct nationalityname
from dbo.profile) t -- this is alias
In SQL Server, You need to give alias to sub-queries used in FROM clause.

How to print 1 ,2,3..10 number in one column using sql query [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I am using 11g RDBMS and in one interview interviewer ask me that print 1 to 10 numbers using SQL query don't use loop if you are using PLSQL, means using select query he wants to see the result.
like Table:
1
2
3
Here are two approaches, both are SQL Server syntax, but you will find something similar for other RDBMs:
--ROW_NUMBER()
SELECT TOP 10 ROW_NUMBER() OVER(ORDER BY (SELECT NULL)) FROM sys.objects; --any table with more rows than 10 will do
--recursive CTE
WITH recursiveCounter AS
(
SELECT 1 AS Nr
UNION ALL
SELECT r.Nr+1
FROM recursiveCounter AS r
WHERE r.Nr<10
)
SELECT * FROM recursiveCounter

Start to display result from the second row [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I have a simple question: I would like to know how to display records from my database starting from the second record.
Thank you!
If you have a column that specifies the ordering, the ANSI standard way to do this is:
select t.*
from table t
order by col
offset 1 row;
Try this:
select * from
(select
*,
ROW_NUMBER() over (order by TableId) as rn
from TableName) dane where rn>1
in MSSQL.

sql query with ORDERBY and ROWNUM [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
The following query
SELECT JOB_TYPE, CLASS, JOB_RUN_START, JOB_RUN_FINISH, JOB_STATUS, JOB_PID FROM
(SELECT * FROM ARCHIVE_JOBS ORDERBY JOB_RUN_START ASC ) WHERE ROWNUM <=6;
yields to an error:
ERROR at line 1: ORA-00907: missing right parenthesis
Anybody know why?
It's order by and you missed aliasing your subquery. I used X as alias name
SELECT JOB_TYPE, CLASS, JOB_RUN_START, JOB_RUN_FINISH, JOB_STATUS, JOB_PID
FROM
(
SELECT * FROM ARCHIVE_JOBS
ORDER BY JOB_RUN_START ASC
) X
WHERE ROWNUM <=6;
try to replace ORDERBY by ORDER BY
ORDERBY is not a keyword, so it's considered by mysql as in the FROM part of the query (i.e. a table), and table list should be separated by ,

Using multiple CTEs in one statement [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I want to use multiple CTEs in my query, but I haven't been able to get it working. The following is an example of what I would like to do:
WITH tbl1 AS
(SELECT *
FROM tblStuff)
WITH tbl2 AS
(SELECT tbl1.fldStuff1 ...
FROM tbl1, tblStuff2)
SELECT *
FROM tbl2
You only need to specify WITH once. Then you can list additional CTEs separated by a comma. E.g.:
WITH cte1 AS
(
...
),
cte2 AS
(
...
)
SELECT ...;
WITH tbl1 AS
(SELECT *
FROM tblStuff),
tbl2 AS
(SELECT tbl1.fldStuff1, tbl1.fldStuff2, tblStuff2.fldStuff1, tblStuff2.fldStuff2
FROM tbl1, tblStuff2)
SELECT *
FROM tbl2
When you use multiple CTEs, no need for the extra WITH, seperate with a comma.