Skip to content

Tag: sql

Provide array of ids and get rows with repeated rows

I have the table where I wand to do a query to get same rows multiply times Races Table: id name location 1 fast race London 2 cool race New York 3 super race Berlin I want to do query where I will search races in table by id and get results with repeated rows something like this And get

LIMIT 1 by Column On Query Returning Multiple Results?

I have a user_certifications table, with these props: So, a user can be listed multiple times with a variety of certs. I have a list of user_ids for which I need to get ONLY the most recently updated record. So for one user it would be: How do I do this efficiently if I need ONLY the last dated entry

sql find parent table where sum of child column not equal to parent column

hey guys i am trying to find the a bill from billMaster where the sum of billDetails.total is not equal to billMaster.remainingAmount NB this is a one to many relationship where one bill can contain more billdetails i tried the below query and got an sql error both queries returned the same error i gess its o…

SQL Select One Record over another based on column value

What I am trying to do is select rows based off of a ‘priority’. Say I have this: I want to choose one row each for the control ids (the whole row), which would be the third row, because there is no priority, and the 2nd row becuase it has priority. So if I have two control IDs that are

How to sum and pivot a table in SQL?

I have the following table: col_a col_b col_c 1 0 1 0 1 0 I want to sum up each column and assign a value to it based on the output, with the output like-so below: column sum string col_a 1 ‘string one’ col_b 1 ‘string two’ col_b 1 ‘string three’ I’ve tried the follow…