Skip to content
Advertisement

Tag: sql

Simplify SQL query with string as array parameters

I’m trying to find a way to simplify my stored procedure. When I try to query using single parameter it went well but when using array, the retrieval process took so long. Any idea how will I simplify this? Someone suggested to me to put StringAsArray into temp table but I don’t know exactly what they’re trying to suggest. Any

Error Code: 1242. Subquery returns more than 1 row in Attribute Subquery

I’m trying to get the difference between two dates deathtime and admittime using subquery in attribute list. This is the script that I run: It returns Error Code: 1242. Subquery returns more than 1 row when I run it. Would really appreciate any help. Answer The reason why you’re getting that error is because a subquery can’t return more than

Capturing difference between 2 tables in one table

I understand my mistake with creating questions in StackOverflow, so I want to rewrite my question. I have two tables. One of them is my target table with old data and the source table with new data. Implicitly I want to compare these 2 tables and get information on which columns have been changed and changed status. So I created

Find numeric record number in string

I’ve been using this site for longer than I can remember, but I’ve never had to ask a question before – I’ve always been able to find what I need – but this one could use some SQL expertise for the best approach since it’s kind of a worst case. I have a text comment field that gets a lot

Concate values of a certain column in a different column depending on id in SQL

id col1 1 John 1 Mary 2 Patricia 2 Charlie 3 Jane 3 Karen 3 MJ 3 Roland The output should look like this id values 1 John,Mary 2 Patricia, Charlie 3 Jane, Karen, MJ,Roland Answer In MySQL, MariaDB and SQLite, you can use the GROUP_CONCAT aggregation function: In PostgreSQL and SQL Server, you can use the STRING_AGG aggregation function:

NULL in SQL need it Removed [closed]

Closed. This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 7 months ago. Improve this question I would like to remove the “Null” in my week Column. Any help? I tried screenshots provided error what i

PostgreSQL: Create array by grouping values of the same id

Given the following input data: id category 1 A 1 B 2 A 2 R 2 C 3 Z I aim aiming to get the following output table: id categories 1 {“A”,”B”} 2 {“A”,”R”,”C”} 3 {“Z”} using the following query: But what I get is the following table: id categories 1 {“A”,”B”,”R”,”C”,”Z”} 2 {“A”,”B”,”R”,”C”,”Z”} 3 {“A”,”B”,”R”,”C”,”Z”} How can I obtain

How to join two total tables using sql?

For a university work we have two tables in sql: table1: table2: I need to join the two tables by adding the total number of people in each city. So I tried to do: However, if a city A appears in table 1 and does not appear in table 2 this would not work. The same would happen if a

Advertisement