Skip to content

Tag: sql

SQL Query to remove duplicated data and take single column sum

I have the following table resulted from but now I want to remove the repeated rows except the Sum of ‘TotalBill’. Answer Use GROUP BY: Note that for the billing date, the two “duplicate” records you have highlighted have different dates. It is not clear which date, if any, you want to…

Is this a perfect SQL query to fetch random items

I have this below query to fetch books of a random author and order by the books last modified date. Because I am new to SQL something tells me this query can be improved and simplified. I would appreciate the help of the SQL experts, if this is already simplified then I will consider myself an SQL expert :).…

Can I combine parts of multiple columns in Oracle SQL

I’m a student in college and I’m working on a project with Oracle DB. I was wondering if it was possible to make a column value appear as concatenated parts of other columns when I Insert a line and use that column as PK ? So on a table like this : So when I insert a line I’d like

MySQL join dataset on at least X items

My question in a SQL Fiddle. How can I join all elements in table A with all elements in table B via a many-to-many mapping table, even if no relationship exists? My LEFT JOIN solution isn’t giving the results I expect. Details: Given these tables: And this seed data: I need a report like this: The quer…

SQL pivot the column values

Problem Statement: Pivot the Occupation column in OCCUPATIONS so that each Name is sorted alphabetically and displayed underneath its corresponding Occupation. The output column headers should be Doctor, Professor, Singer, and Actor, respectively. Note: Print NULL when there are no more names corresponding to…

SQL: select the last values before a space in a string

I have a set of strings like this: I need to extract only the last values from the right and before the space, like: how will the select statement look like? I tried using the below statement, but it did not work. Answer Perhaps the simplest method in SQL Server is: This is perhaps not the most performant met…