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

  • SEARCH
  • Home
  • 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 8277805
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T08:48:06+00:00 2026-06-08T08:48:06+00:00

Suppose I have a table with lots of rows and columns (alias: bigtable), and

  • 0

Suppose I have a table with lots of rows and columns (alias: bigtable), and a table that always has 1 row, but multiple columns (alias: 1rowtable). The 1rowtable has nothing to do with bigtable, it is just there for some settings my script uses that are modified dynamically. So I cannot use static SQLCMD variables for that and I cannot use normal variables for that either because my script has GO statements.

Now I want to write a select statement that accesses BOTH tables.

If I do:

SELECT ... FROM bigtable, 1rowtable

it does a CROSS JOIN so that is bad, can’t go that route.

If I use a CTE for 1rowtable, I have to access its fields with

SELECT field FROM 1rowtable

So that is bad too. Same with a table valued function like:

CREATE FUNCTION getSetting(@name nvarchar(40))
RETURNS TABLE
AS
RETURN (SELECT name FROM 1rowtable WHERE name = @name)

Obviously I cannot use a scalar function at all because it only returns a specific datatype, but the settings have different datatypes. Yet, obviously I would like to use it LIKE a scalar function of course without doing the ‘SELECT .. FROM dbo.getfieldfrom1rowtable(..)’ stuff, since I am using the 1rowtable rather often in queries.

I also tried doing:

SELECT
  (SELECT
     <expression involving bigtable and 1rowtable>,
     <expression involving bigtable and 1rowtable>,
     <expression involving bigtable and 1rowtable>,
     ...
  FROM 1rowtable)
FROM bigtable

But of course a subselect cannot select more than one item if it does not begin with exists…

So what should I do? It seems I will have to continue using ‘SELECT .. FROM dbo.getfieldfrom1rowtable(..)’ every time? Just curious 🙂

PS. ms sql server 2008r2

  • 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-08T08:48:08+00:00Added an answer on June 8, 2026 at 8:48 am

    There is nothing wrong with using a cross join to bring together rows from tables, particularly when one only has one row.

    Use the syntax:

    select bt.*, ort.*
    from bigtable bt cross join
         onerowtable ort
    

    There is nothing inherently “wrong” with cross joins, when they are used correctly. The problem is when they are used inadvertently. If you cross join two tables with a million rows . . . well, your temp space is going to fill up, your processor(s) will be very busy, and the query will eventually crash due to a lack of resources.

    However, cross joining a table with one row to another table poses no problems at all.

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

Sidebar

Related Questions

Suppose I have a table with the columns: `id`,`firstname`,`lastname` With some rows like: '1','bob','marley'
Suppose I have table tags which has a field count that indicates how many
Suppose I have a table called Companies that has a DepartmentID column. There's also
Suppose I have a table with lots of rows identified by a unique ID.
Suppose I have table A with a field that can be either 1 or
Suppose I have a table, the first column is an identity. I thought that
Suppose I have a table abc with columns p_id , u_id , and comments
Suppose I have a table with the following columns (a list of words): word:
Suppose I have a table that contains valid data. I would like to modify
Suppose I have a table with columns (DayId, RunningTotal): DayId RunningTotal --------------------- 1 25

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.