I have multiple SQL queries that look similar where one uses JOIN and another LEFT OUTER JOIN. I played around with SQL and found that it the same results are returned. The codebase uses JOIN and LEFT OUTER JOIN interchangeably. While LEFT JOIN seems to be interchangeable with LEFT OUTER JOIN, I cannot I cann…
Tag: join
Speed up joins on thousands of rows
I have two tables that look something along the lines of: And a query to get data from t1. The query runs fine and takes a few ms to get data from it, although problems start appearing when I use joins. Here’s an example of one of my queries: Which can return a few thousand rows, that might look somethi…
Sum of two counts from one table with additional data from another table
I have two tables as follows: I want to get the sum of two counts, which are the number of true values in col_a and number of true values in col_b. I want to group that data by user_id. I also want to join Table B and get the name of each user. The result would look like this: So
How to add a query to a table in SQL?
I have 3 tables. For simplicity I changed them to these sample tables. table1: CorporateActionSmmary table2# ProductMaster table3# OpenPosition First I need to add ISIN from table2 to table1 table1: CorporateActionSmmary So, I used this code Now as you can see the Quantity is missing in Table1 so I have to ad…
SQL for identifying % of orders placed within 20 minutes of each other
Have a dataset like below and would like to know various ways to solve the question of : what % of orders were within 20 minutes of each other? CustomerId Order_# Order_Date 123 000112 12/25/2011 10:30 123 000113 12/25/2011 10:35 123 000114 12/25/2011 10:45 123 000115 12/25/2011 10:55 456 000113 12/25/2011 10…
MySQL Query – Pending Friends Approval / Relationship between user & friends
I have two tables: g_relationships (id,request_id,receiver_id,status,approved) g_users (which contains: id,username,…) I have a hard time making a query that adds a temporary column, checks whether userid: 4 exists in request_id or receiver_id column, and take the other userid and fetch username from g_…
Joining tables based on datetime2 predicate
How do I join tables A and B (see pic) on TripID and where TimeTriggered is between SegmentStart and SegmentEnd? I could try: However since BETWEEN is inclusive on both ends it would join alarm B to both segment 1 and 2. I could try >= AND < but it would leave out alarm C. I could try > AND
How can I get a value when the master table of the outer join is empty?
I have created a table where I get the sum of each item. However, this query returns : 0 row affected. I know what the problem is. If the key_id and cust_id are not in the t1 table specified as an alias, the value cannot be returned because the t1 table is empty. If there is data for key_id in
Using NVL with JOIN
I want to display 2 values in table but only Student 301 is displayed. Student 102 doesn’t received any grades. I joined two tables. Here’s my query. Thanks for your help Answer Presumably, both students are in enrollment_info. If so, you can use: Note the use of LEFT JOIN. The table where you wan…
Joining table only once in SQL
I’m sure this is very basic, but I’ve hit a brick wall. First post here, long time reader. I’ve got two tables, one is a list of customers, one is a list of their activity by month. For some unknown reason, some of the data in the activity column is duplicated and it’s causing me error…