Questions tagged [outer-apply]

65 questions
24
votes
2 answers

Where to use Outer Apply

MASTER TABLE x------x--------------------x | Id | Name | x------x--------------------x | 1 | A | | 2 | B | | 3 | C | x------x--------------------x DETAILS…
Sarath Subramanian
  • 20,027
  • 11
  • 82
  • 86
16
votes
3 answers

The value is returned instead of NULL when using function with OUTER APPLY

I am getting strange results when using inline function. Here is the code: IF EXISTS ( SELECT * FROM sys.objects AS o WHERE name = 'vendor_relation_users' ) DROP FUNCTION dbo.vendor_relation_users; GO CREATE FUNCTION [dbo].[vendor_relation_users] ( …
Dmitrij Kultasev
  • 5,447
  • 5
  • 44
  • 88
15
votes
4 answers

Parent count based on pairing of multiple children

In the below example, I'm trying to count the number of drinks I can make based on the availability of ingredients per bar location that I have. To further clarify, as seen in the below example: based on the figures highlighted in the chart below; I…
SMHorus
  • 165
  • 6
15
votes
2 answers

Entity Framework and CROSS/OUTER APPLY

I want to create some test cases for Entity Framework queries that surely generate SQL commands that contain CROSS APPLY or OUTER APPLY operators. Could someone show typical scenarios where these kind of SQL queries appear?
tamasf
  • 1,068
  • 2
  • 10
  • 22
6
votes
2 answers

Is there any difference between CROSS APPLY and OUTER APPLY when creating a cartesian product?

When creating a cartesian product between two tables, is there any difference between CROSS APPLY and OUTER APPLY? This may seem like a silly question given that without a relationship expressed between the tables, the right-hand table can't fail to…
T.J. Crowder
  • 1,031,962
  • 187
  • 1,923
  • 1,875
6
votes
2 answers

Is there any alternative for OUTER APPLY in Oracle?

In the following example, I pass tbA.ID to tbC query. In this case, I used OUTER APPLY operator of SqlServer. SELECT ... FROM (SELECT ID FROM TableA ...) tbA OUTER APPLY (SELECT ... FROM TableB tbB WHERE tbA.ID = tbB.ID) tbC ... In Oracle, we…
user1389591
4
votes
1 answer

OUTER APPLY in BigQuery

I want to apply a column to a list of users where I pull the latest sign in date . Traditionally I would do something like this: SELECT U.* , O.* FROM Users.Users U OUTER APPLY ( SELECT .. FROM .. Events.Events E WHERE E.UserId = U.UserId)…
Agneum
  • 727
  • 7
  • 23
4
votes
3 answers

OUTER apply without subquery

I went through an article about CROSS APPLY and OUTER APPLYin SQL Server. The following tables were used to illustrate both. Employee table : EmployeeID FirstName LastName DepartmentID 1 Orlando Gee 1 2 Keith …
bmsqldev
  • 2,627
  • 10
  • 31
  • 65
3
votes
1 answer

T-SQL to LINQ to SQL using Navigation Properties

I can’t seem to come up with the right corresponding LINQ to SQL statement to generate the following T-SQL. Essentially, I'm trying to return payment information with only one of the customer's addresses... the AR address, if it exists, then the…
2
votes
2 answers

SQL Server JOIN/APPLY Query

What join should I use to get my desired output base on dummy table below DETAIL TABLE x------------------------------x | empID | empName | date | x------------------------------x | 1 | emp1 | 10/01/2016 | | 1 | emp1 | 10/03/2016…
Devs
  • 65
  • 8
2
votes
2 answers

Using OUTER APPLY with Codeigniter active record

Is it possible to use SQL Server's OUTER APPLY with Codeignter's Active Record?
Tom
  • 12,776
  • 48
  • 145
  • 240
1
vote
1 answer

SQL: How to resolve varchar numeric conversion using OUTER APPLY and SELECT TOP (1)?

I have a base table with invoices for different stock codes, the important fields are: StockCode InvoiceDate AAA 2022-01-01 AAA 2022-05-01 BBB 2022-02-01 BBB 2022-11-01 I am trying to work back to the cost price of those items…
1
vote
1 answer

Using .NET Core nested LINQ instruction in migration from SQL Server to MySQL

In the web application I'm developing, I'm using .NET Core 3.1 and SQL Server in a Windows environment. In the support code of a cshtml page, I've created a LINQ query to get information from multiple tables of the database. Here is the code…
Leonardo Daga
  • 135
  • 1
  • 12
1
vote
1 answer

ORacle outer apply combination with group by

why this two queries have two different result : First query: select c.customer_id, oo.order_id from co.CUSTOMERS c outer apply (select * from co.orders o where…
atufi
  • 11
  • 3
1
vote
2 answers

How to join 2 tables without common key and randomly generate rows of second table

I have 2 tables.. [Users] and [Questions] Users Table has.. UserId Name -- ---- 1 Bob 2 Ang 3 Bill And Question Table has.. QuestId Description CategoryId ------- ---------- -------- 0 Question0 1 1 Question1 1 2…
Jhe
  • 97
  • 1
  • 7
1
2 3 4 5