Example We are looking to join rhs_table onto lhs_table for the playerIds. Every person in lhs_table has a corresponding row in rhs_table, however the joins are not so simple: For Nia Johnson Jr., Jr. is missing in rhs_table For Kay Sieper, her full name Kayla is used in rhs_table We want to ignore (ie not le…
Tag: sql
Oracle Hierarchical Query at depth level
I have a requirement to build a table from a hierarchical table. Table structure as below: emp_hier table: emp_id supervisorId 100 null 1 100 2 1 3 2 New table: I have to write a select query on the emp_heir table and the selected data should look like this: sel_emp_id rel_emp_id relation depth_lvl 100 100 se…
Select Distinct Rows with complex criteria
I have a table generated from a CRM software and it has a lot of repited individuals in different rows but with different fields completed in each repetition, something like this: id birth_date sex postal_code customer smoker 001 NULL NULL 00067 Yes 1 001 NULL Male 00067 NULL 1 001 21/03/1994 NULL 00067 NULL …
Group By function
hope you all having a great day. I need some help with this query. Just to explain the situation, I have to send e-mails containing the data found in this select, but I have to group by customers (TBLOTE.CEMPRES) so it would build a single e-mail for each customer found. Example, if the query finds 3+ row for…
C# Is it safe to concatenate constant strings to form a SQL Query?
I need to change the table name dynamically based on specific conditions. Is it safe to build my sql query the following way or am I prone to SQL Injection? To generalize, I want to build a parameterized sql query string by concatenating constant strings. Answer While this should not present any security prob…
Select range in SQL
I have a sql database that have InvoiceNumber column Now i need to select range between two numbers, but i don’t know what happened. I’ve tried “Between” and “<= , >=” Statements but the results are same. Table My query For example: If i need range between “1300…
Calculate the difference of dates in one column
DB-Fiddle Expected result: I want to calculate the date_difference between the MAX and the MIN order_date per campaign. So far I was able to come up with this query: This solution would work if the dates would be in two separate columns. How do I have to modify the query to also make it work if they are in on…
Count the total number of records before a specific day for the last N days in SQL
I have a table that stores customer information including their registration date with the service. I would like to know the total number of subscribed customers (from the beginning of the service up until that day) at the end of the day for the past 10 days. I imagine the solution would be something similar …
SQL Joins not working correctly when no data present
I’ve got the following code, where I build a tag from an entity Each tag has an id, name, description and how many questions it has, how many it has in a day, and how many it has in a week. The problem is, I can’t seem to display tags that have no questions tied to them, and also if
Need SQLQuery with Stored procedure with below example
I have the following MySQL-table the average must be using stored procedure, not normal query. I have normal SQL Query I want that to look like this, with a MySQL query: Answer If the Id’s on your table are unique, you can do it like this (you were pretty close… just the case when was missed in yo…