Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8835847
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T09:21:17+00:00 2026-06-14T09:21:17+00:00

I was writing a query in t-sql that uses a function in a sub

  • 0

I was writing a query in t-sql that uses a function in a sub query and came across two questions.
Imagine an advertisement table as follows :

AdID- Name

An Options table as follows :

OptionID - OptionName

And a junk table (AdvertisementOptionLink) between these two with two foreign key columns :

AdID - OptionID

Now I want to query the advertisement as user selects the options .
I had written a query like this :

SELECT * FROM Advertisement ad
INNER JOIN AdvertisementOptionLink aol
WHERE ad.AdvertisementID IN (SELECT AdvertisementID FROM UDF_GetAdvertisements)

Now UDF_GetAdvertisements is a table valued function that returns list of advertisement that had the specific options.

There are two questions :

  1. Is This UDF_GetAdvertisements function queries all the data for each row ? I mean if I`ve got like 2000 advertisement in my table is it gonna query all those and return all the advertisementIDs? Am i better off saving the function return value in a variable ?

2.In this database there are some advertisement without any options how can I return all advertisement if user selects no options ?

Im using Table-Valued Parameters in t-sql to pass the selected option IDs through a stored procedure.
Used a little help from this page : http://www.sommarskog.se/arrays-in-sql-2008.html

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T09:21:18+00:00Added an answer on June 14, 2026 at 9:21 am

    You would need to check the execution plan.

    WHERE ad.AdvertisementID IN (SELECT AdvertisementID FROM UDF_GetAdvertisements)
    

    will be implemented as a logical semi join operator. The physical join type might be any of merge, hash, or nested loops.

    Merge join and Hash join process each input once. Nested loops processes the outer input once and the inner one as many times as there are rows in the outer input. But even if the TVF is shown on the inner side of a nested loops join the result might be cached in a spool rather than repeatedly re-evaluating the TVF.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wrote a sql join query in oracle with two table. While writing query
I am writing a query that uses the CONTAINSTABLE function. For the third parameter
I'm writing a PHP script that builds an SQL query by concatenating the string
Possible Duplicate: Writing an SQL query to SELECT item from the following table I
I am re-writing a query that was generated by Business Objects and uses old-fashioned
Writing a SQL query that should return the average charges for a preceding 91
I'm writing a Rails 3 ActiveRecord query using the where syntax, that uses both
I'm writing a query that uses input from a search form where Brand, Type
I need help writing a T-SQL query that will generate 52 rows of data
I'm writing a linq-to-sql query that joins 4 tables. I have something like this:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.