There is a many-to-many relationship between A and B. There are 3 tables to represent that relationship. TableA, TableB, TableAB Now I have another table TableC where it has a foreign key to TableA, and I want to filter objects from TableC where it has a relationship with TableB. The following is high-level c…
Tag: sql
Include one table’s values in multiple other tables and allow FK references
I’m still a relative novice when it comes to designing SQL databases, so apologies if this is something obvious that I’m missing. I have a few tables of controlled vocabularies for certain values that I’m representing as FKs referencing the controlled vocab tables (there are few distinct voc…
How can I count the number of zeros in all columns for a table in oracle sql
Suppose you have a database table named db_table1 with hundreds of columns and most of them contain lots of 0’s. I’m trying to count zeros for each column and divide it by the length of column so I can see the ratio of zeros in each column. The below code gives me the ratio of nulls in each column…
Remove duplicate columns after using join on in sql
I have the following sql query that joins two select statements on two columns The query produces the following output. | Name | ItemNum |TicketNum |TicketNum |ItemNum | But I would like the output to be | Name | ItemNum |TicketNum | Answer Solution 1: Specify the column names like this Solution 2:
How can I join two tables on an ID and a DATE RANGE in SQL
I have 2 query result tables containing records for different assessments. There are RAssessments and NAssessments which make up a complete review. The aim is to eventually determine which reviews were completed. I would like to join the two tables on the ID, and on the date, HOWEVER the date each assessment …
How can I join 4 tables
Please help to modify the below code. I want to join these two select queries such that I can get a single output with records from two diff tables ? I have 4 tables, table_a has the user id that I have to use to search table_b1 has the foreign key for table_c which has the name that I want
Get same employeeid who belongs to different deptno at a particular interval
I am trying to list each employee who belongs more than one dept for a given period of time. Empid Dept Date 001 10 10/02/2022 002 20 10/02/2022 003 30 10/02/2022 001 20 10/02/2022 002 30 10/02/2022 001 10 11/02/2022 002 20 11/02/2022 003 30 11/02/2022 001 20 11/02/2022 002 30 11/02/2022 From the above source…
mysql return people with similar purchase and desc order by count of similar items
customers table id name 1 a 2 b 3 c 4 d purchase table product_id customer_id x 1 y 1 x 4 y 4 x 3 z 2 the customer table has customer data and purchase table has order data. Now coming to question, I want customers id who bought similar products ordered by the count of similar items eg:
Query with Group and name sorting
I am trying to build a SQL query that is bit more complicated to what I am used to writing. Example data: So far I have a working query Currently it will return But I would like that query to always returns the names with biggest event_id, so good results would be “[Lpr] abc” and “[Lpr] Name…
How to display an individual with highest number of posts and an individual with lowest number of posts at the same time in SQL Server?
Below is the table I have created and I have also inserted values in it: Now I am trying to solve the following question: Write a query that displays the team members who have published the highest and lowest number of posts. This is what I have done: I received the following result: I almost got my desired r…