Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa SQL SQL Union with order by

Have Programming Question? Ask it here!
 
 
 


Pushpa Sheela
SQL Union with order by
0 Answer(s)      3 years and 9 months ago
Posted in : SQL


I want to combine three queries using union.

1.SELECT * from user_projects where status='O' order by id desc

It returns the following ids

115,112,111,106,5,4,3

Second query

2.select * from userprojects where status!='F' and status!='D' and status!='O' and newproject='yes' order by id desc

It returns the following ids

114,113,105,104,103,102,101,100,99

3.select * from userprojects where status!='F' and status!='D' and status!='O' and newproject='no'

It returns the following ids

110,109,108,107,98,97,96

But i am combine the three queries using union

(SELECT * from userprojects where status='O' order by id desc) union all (select * from userprojects where status!='F' and status!='D' and status!='O' and newproject='yes' order by id desc ) union all (select * from userprojects where status!='F' and status!='D' and status!='O' and new_project='no' order by id desc)

it return

3,4,5,106,111,112,115,99,100,......96,97...................

But i want

115,112,111,106,5,4,3,114,113,105,104,103,.........110,109,108........

Please any one help me


Advertisement
View Answers

Related Tutorials/Questions & Answers:
SQL Union with order by
SQL Union with order by  I want to combine three queries using union... status='O' order by id desc) union all (select * from userprojects where status!='F' and status!='D' and status!='O' and newproject='yes' order by id desc ) union
SQL UNION Operator
SQL UNION Operator      ... The Tutorial helps you to understand SQL UNION Operator .In this Tutorial, we... 5 Santosh 12 SQL UNION Syntax The Syntax
Advertisements
What is the difference between UNION and UNION ALL in SQL?
What is the difference between UNION and UNION ALL in SQL?  What is the difference between UNION and UNION ALL in SQL?   Hi, UNION is an SQL keyword used to merge the results of two or more tables using a Select
SQL Union
SQL Union       SQL Union is used to combine the query of two or more Select Statement... 'SQL Union'. To understand and grasp the example we create a table 'stu
merge tables in sql using union
merge tables in sql using union  How to create a new table in database by merging two tables using union function in SQL?   REATE TABLE new_table SELECT * FROM table1 UNION SELECT * FROM table2;   
SQL ORDER BY
SQL ORDER BY      ... 1 Komal 10 SQL ORDER BY Syntax.... SELECT ColumnName(s) FROM TableName ORDER BY ColumnName(s) SQL
SQL UNION ALL Operator
SQL UNION ALL Operator       The SQL UNION ALL Operator is used to list all records from  two or more select statements. The SQL Union ALL  Operator
union
union  how to declare union function define in single line in java(eg:like c=a+b
SQL UNION Operator
SQL UNION Operator      ... The Tutorial helps you to understand SQL UNION Operator .In this Tutorial, we... 5 Santosh 12 SQL UNION Syntax The Syntax
SQL ORDER BY
SQL ORDER BY      ... 1 Komal 10 SQL ORDER BY Syntax The ORDER.... SELECT ColumnName(s) FROM TableName ORDER BY ColumnName(s) SQL
PHP SQL ORDER BY
PHP SQL ORDER BY       This example illustrates how to execute query with ORDER BY clause in the php application. ORDER BY clause is used to sort the result data either
order
order   write a java code to enter order of number of chocolates(bar,powder,giftbox) in arraylist. Also consider exceptional cases like entering integer in name use try,catch ,throw to deal with exception
Php Sql ORDER BY
Php Sql ORDER BY  This example illustrates how to execute query with ORDER BY clause in the php application. In this example we create a php page.... SQL allows for sorting of retrieved data with the ORDER BY clause
Composable Pointcut - Union
ComposablePointcut- Union Operation A composable pointcuts can be composed using the static methods in the org.springframework.aop.support.Pointcuts class or using composable pointcut class in the same package. MainClaz.java
HQL order by.
HQL order by.  HQL Order by query giving problem.   Order... mention, order by automatically sorted the list in ascending order. Here is an example of order by clause. Since we didn?t mention ?asce? or ?desc? it will return
MySQL Order By
(`emp_id`)  ) Use Order By in a sql query: (Ascending... employee ORDER BY(emp_salary) asc; Output: Use Order By in a sql query... MySQL Order By      
Ascending order
of them equal to each other, in any order, (for example, 23, 7, 156; but not 23, 7, 23), and then it should print out the three integers in ascending order, saying
JavaScript array union
JavaScript array union   ... union in Java Script. The code contain a script that include a variable arr1.... The document. write print the list of array union element with no duplication
SQL statement - SQL
SELECT SUM(od_vat) FROM tbl_order WHERE od_id = $orderId UNION...SQL statement  Hi, i have an sql statement that needs to add... be charged 10. otherwise nothing. Heres the code: $orderAmount = 0; $sql
sql - SQL
order by SQL Query  What is order by in SQL and when this query is used in SQL?Thanks!  Hi,In case of mysql you can user following query.Select salary from salary_table order by salary desc limit 3,1Thanks
Order Entry System
Order Entry System  Create a new order entry system using netbeans and microsoft access.can anyone help me
sql
difference between sql and oracle  what is the difference between sql and oracle
sql
sql  how to get first row in sql with using where condition in sql? how to get last row in sql with using where condition in sql
Maven's order of inheritance
Maven's order of inheritance  hello, What is Maven's order of inheritance?   hii, 1.parent pom 2.project pom 3.settings 4.CLI parameters
How I call the function union from the main - Java Interview Questions
How I call the function union from the main  Please, from public static void main(String[] args) I would like to call the function union and I... = new boolean[rows][columns]; } public Relation union(Relation mat
sql
sql  I want interview sql questions   Please visit the following link: SQL Tutorials
SQL
tables EMP, and DEPT, the structure for which are given above. Write SQL queries...??. Display all employee names and employee numbers in the alphabetical order
Sql
Sql  how to find maximum of a101,a102,a103 from a table in sql
SQL
SQL  hii What is sql?   hello, SQL, which stands for Structured Query Language, is a special-purpose language used to define, access, and manipulate data. SQL is non procedural, meaning that it describes
sql
sql  how to display the values in the same order as i entered from a certain table
ascending order of a data hierarchy
ascending order of a data hierarchy  The ascending order of a data hierarchy is 1. Bit-byte-record-field-file-database 2. Byte-bit-field-record-file-database 3. Byte-bit-record-file-field-database 4. Bit-byte-field-record-file
sql
sql  returning value from a store procedure in sql with example   Please visit the following links: http://www.roseindia.net/mysql/mysql5/stored-procedures-and-functions.shtml http://www.roseindia.net/sql/create
Alphabetically sorting order
sorted order   Hi Friend, Try the following code: import...(st); } System.out.println("ArrayList Elements in Sorted order
SQL
SQL  In my computer i have microsoft sql 2008.how can i set that in the cmd.i want to use that in cmd.what is the default username and password
Reverse Order Java
Reverse Order Java   I am trying to get this into reverse order. Does... in reverse order: "); for (int i = numbers.length-1; i >=0; i...); System.out.println("Numbers in reverse order: "); for (int i = numbers.length-1; i
Alphabetical order - Java Beginners
clicked the view button Now i want to display the files in alphabetical order
SQl
SQl  . Given two tables: table1(player, groundname, numcenturies); table2(ground_name, country); Write and SQL query for the following: " Select all the players from table1 who has
Pizza Order..?? - Java Beginners
Pizza Order..??  Define a class PizzaOrder class that contains a list... the cost of the entire order. Small pizza costs RM9.90, a medium pizza... wantMore = "n"; PizzaOrder order = new PizzaOrder(); do { order.pepporoni
SQL
SQL   1)How to Store 1000 records in Oracle object. 2)Write a query for calculate highest, 3rd Highest & 10th highest salary from emp teble. 3)What is Sequence. 4)How to use rowid in Sql. 5)What is Views. 6)How
Alphabetical order - Java Beginners
in alphabetical order of ID. How can i implement this... Pls Help..:) Thanks
SQL
SQL  how to get ( 15 march 2011) and (15/03/2011) output using SQL   Use the following queries to get the data from database in the given format. For (15 march 2011) format: SELECT DATE_FORMAT(dob, '%d %M %Y') FROM
SQL
SQL  how to get ( 15 march 2011) and (15/03/2011) output using SQL   Use the following queries to get the data from database in the given format. For (15 march 2011) format: SELECT DATE_FORMAT(dob, '%d %M %Y') FROM
SQL
SQL Trigger query  Why we use the Trigger and what it's uses?   A database trigger is procedural code that is automatically executed..., user events, and SQL statements to subscribing applications 10)Restrict DML
Mysql ASC Order
Mysql ASC Order       Mysql ASC Order is used to sort the result set by ascending or descending order. The Order by CLAUSE sort the result by specified column. Understand
Mysql Date Order
Mysql Date Order       Mysql Date Order is used to sort the records from a table in ascending order or descending order. Understand with Example The Tutorial illustrate an example
SQL
events, user events, and SQL statements to subscribing applications 10)Restrict DML
SQL
, user events, and SQL statements to subscribing applications 10)Restrict DML
SQL
events, and SQL statements to subscribing applications 10)Restrict DML
SQL
primarily with Trusted Oracle. Order of SQL statement execution Where clause, Group... SQL       SQL SQL is an English like language consisting of commands to store, retrieve
Order of list in java Vs Haskell.
Order of list in java Vs Haskell.  How to order of [1,2,3] to [1,2,3,2,1]in java
 

 

 

DMCA.com