Linked Questions

0 votes
1 answer
639 views

Mysql union order by not working [duplicate]

This is the query I am running: SELECT * FROM ( (SELECT wp_posts.*, wp_postmeta.meta_value AS views FROM wp_posts INNER JOIN wp_postmeta ON ( wp_posts.ID = wp_postmeta.post_id ) WHERE 1=1 AND ...
tuscan88's user avatar
  • 5,819
-1 votes
1 answer
59 views

merge two sql tables [duplicate]

I have two SQL tables that are not related to each other. But I need these two to show me the name. The queries are: SELECT ca_nombre FROM cancion ORDER BY ca_nombre ASC; SELECT bai_nombre FROM ...
Maicol Rojas's user avatar
19 votes
4 answers
25k views

Apply "ORDER BY" on a "UNION" (Mysql)

So, everything is in the title. I am looking to merge the result of two requests and order the result together (as in, not one after the other). => I was thinking of applying a union and ordering ...
Quiche's user avatar
  • 301
20 votes
7 answers
38k views

SQL massive performance difference using SELECT TOP x even when x is much higher than selected rows

I'm selecting some rows from a table valued function but have found an inexplicable massive performance difference by putting SELECT TOP in the query. SELECT col1, col2, col3 etc FROM dbo....
bbfire's user avatar
  • 3,588
5 votes
5 answers
14k views

How to add order by for Union result?

In SQL Server 2008, we can use Union/Unino All to put two results together, but I want to add order by for the final result. How can do that? What I want is something like: select id1 as id, * from ....
KentZhou's user avatar
  • 25.5k
8 votes
3 answers
6k views

SQL request with case in order by throws "(1) 1st ORDER BY term does not match any column in the result set"

I've got a small problem with an SQL cursor. I'm trying to execute an SQL command on android. I'm trying to sort the returned content by cases, but it seems like the system doesn't accept the returned ...
Phil Plückthun's user avatar
2 votes
4 answers
8k views

Merge multiple columns into one column with multiple rows

In PostgreSQL, how can I merge multiple columns into one column with multiple rows? The columns are all boolean, so I want to: Filter for true values only Replace the true value (1) with the name of ...
kitsune's user avatar
  • 25
0 votes
5 answers
1k views

SQL: How to order a union alphabetically?

This is a slightly strange use case admittedly, but how do you order the results of a simple union like this alphabetically? select name from Reviewer union select model from Car;
RDJ's user avatar
  • 4,122
0 votes
3 answers
2k views

Merge multiple queries by single row and order over all

I have three different queries which have one common row (user_id) that should be combined in one query to apply ordering. It should also work if one or more queries result an empty set. Query 1: ...
steveo's user avatar
  • 3
2 votes
3 answers
732 views

Order two parts of a union independently of one another

Is it possible to do something like this: select name from table1 order by name union select name from table2 order by name I know I can do this: select name from table1 union select name from ...
w0051977's user avatar
  • 15.7k
1 vote
2 answers
1k views

how to query mongodb like union of sql

I have resloved this question: db.coll1.aggregate([ { $match:{ $or:[ {time:{$lt:145941000},code:413} ,{time:{$lt:145942000},code:415} ...
Li Da's user avatar
  • 41
0 votes
1 answer
348 views

SQL UNION failed

This is my query: select dept_name, count(*) as student_number from Student s join Department d on s.dept_id=d.dept_id group by dept_name order by student_number desc, dept_name asc UNION select d....
David Belhamou's user avatar
0 votes
1 answer
243 views

Using SQL UNION function

Forgive the basic question but i'm relatively new to SQL. I have a couple of queries that i'd like to use the UNION function on. I think i'm having trouble ordering the items that I have to get the ...
user3812830's user avatar
3 votes
1 answer
107 views

Get the nearest higher and lower rows in SQL

I'm trying to select the first 5 amounts above 2000 and the first 5 below 2000 and return the data in a single resultset. SELECT TOP 5 * FROM bid WHERE amount >= 2000 ORDER BY amount ASC ...
Mark13426's user avatar
  • 2,629
1 vote
2 answers
197 views

Sorting a Union query

I have a pc, laptop and printer table, each of them having a price and model field. I want to create a combined view of price and model number from these three tables, sorted by price. I have the ...
Anupam Saini's user avatar
  • 2,421

15 30 50 per page