New answers tagged

3

After the edit, the question is (at last!) clear. The problem is that the ordering you want is complicated. It's a "gaps-and-islands" problem. You want first to isolate "islands" with same location, i.e. consecutive (when ordered by tldid) rows that have same location and then reorder the rows in those islands based on the tldorder. One way to solve this: ...


1

This is probably best to insert all items at once or at least avoid have to split string on the SQL Server side. You could convert json to xml similar to this: <Order OrderId="" OrderDate="" CustomerId="" Price="300"> <Items> <Item ItemId="103" Qty="2" Price="100" /> <Item ItemId="123" Qty="2" Price="100" /> ...


1

SELECT a, b ... GROUP BY a is asking for trouble. You may have been 'lucky' in 5.5 and 'unlucky' in 5.6. The problem is that any value of b can be shown for each 'group'. Sure, there are cases where a given a maps uniquely to a given b (eg, in a normalization table), but that does not feel like the case here. To see that there is a problem: SET ...


2

I think you could use the following query to get the data you need: SELECT users.username, title, content FROM articles LEFT JOIN users ON articles.author_id = users.id GROUP BY articles.author_id , title ORDER BY articles.author_id ,articles.published DESC; The presentation of it depends on the programming language you will use to display the ...


2

OK,lets try to write a query that: doesn't use variables in any way: is correct and produces the wanted output always: SELECT q.*, 0 as aa_id FROM table1 AS q WHERE q.type = 0 UNION ALL SELECT ans.*, q.acceptedanswerid as aa_id FROM table1 AS q JOIN table1 AS ans ON ans.related = q.id WHERE q.type = 0 AND ans.type = 1 ORDER BY type, ...



Top 50 recent answers are included