I have a topic and topic_comments table. I want to join them both. The join is on topic.id = topic_comments.parent_id. I want to show the topic with latest comment and order by latest comment createdate. And not show duplicate topics. Can anyone help me? So far I have this: This however doesn ‘t show topics without comments. It only returns
Tag: sql-order-by
Why does orderBy in F# not result in an ORDER BY in SQL?
I’m currently working on a small project that uses USA county data. I have no problems ordering the data in a Seq.orderBy, but as there is a sortBy in the query expression I would expect the results to be sorted. This is not the case. Now, the above is what I’m executing, but my results end up looking like so:
MySQL/MariaDB – order by inside subquery
I used the following query with MySQL 5.5 (or previous versions) for years without any problems: SELECT t2.Code from (select Country.Code from Country order by Country.Code desc ) AS t2; The order …
PostgreSQL – order by an array
I have 2 tables – course that contains id and name of the courses and tagCourse that contains tags for each course. I’d like to write a function that searches courses by given array of tags and returns them ordered by quantity of matching tags. However I don’t know how to write it correctly and in an efficient way. Please
How does order by clause works if two values are equal?
This is my NEWSPAPER table. When i run this query It gives this output But in Kevin Loney’s Oracle 10g Complete Reference the output is like this Please help me understand how is it happening? Answer In relational databases, tables are sets and are unordered. The order by clause is used primarily for output purposes (and a few other cases
PostgreSQL – repeating rows from LIMIT OFFSET
I noticed some repeating rows in a paginated recordset. When I run this query: I get: Next query: I get: Why does “foo” appear in both queries? Answer Why does “foo” appear in both queries? Because all rows that are returned have the same value for the status column. In that case the database is free to return the rows
Defining the sort order of children in a hierarchy query
I would like to know the Oracle SQL query that orders the children in a hierarchy query by the sequence_within_parent column. An example data set and query are: create table tasks (task_id …
How to Select and Order By columns not in Groupy By SQL statement – Oracle
I have the following statement: There exists some extra columns in table Positions that I want as output for “display data” but I don’t want in the group by statement. These are Site, Desk Final output would have the following columns: Ideally I’d want the data sorted like: How to achieve this? Answer It does not make sense to include
MySQL: Order by field size/length
Here is a table structure (e.g. test): Field Name Data Type id BIGINT (20) title varchar(25) Description Text A query like: But I would like to order by the field size/length of the field description. The field type will be TEXT or BLOB. Answer The LENGTH function gives the length of string in bytes. If you want to count (multi-byte)
Dynamic order direction
I writing a SP that accepts as parameters column to sort and direction. I don’t want to use dynamic SQL. The problem is with setting the direction parameter. This is the partial code: Answer You could have two near-identical ORDER BY items, one ASC and one DESC, and extend your CASE statement to make one or other of them always