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 6909301
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T08:40:20+00:00 2026-05-27T08:40:20+00:00

I’m selecting rows from a table select name,age from tabl1 I need to add

  • 0

I’m selecting rows from a table

select name,age from tabl1

I need to add another column which should have the same value for the whole result set.
the value is comming from:

select value from config where key = 'company'

How can I combine this into one query ?

The resultset should look like

Name1 | Age1 | SameComapanyName
Name2 | Age2 | SameComapanyName
Name3 | Age3 | SameComapanyName
Name4 | Age4 | SameComapanyName
  • 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-05-27T08:40:21+00:00Added an answer on May 27, 2026 at 8:40 am
    select t.name, t.age, c.value
    from tabl1 t
    cross join config c
    where c.key = 'company'
    

    Added:
    It’s maybe more appropriate when there is need to return more than one column at time from specific table.

    There is a difference in behaviour between this and subquery as a column. When condition c.key = 'company' isn’t met the join won’t return records at all, in case on subquery it returns null value for each row.

    Added (after @alex comment):

    cros join returns NxM records that is true but not in this case. Here where condition limits M to specific row/-s only. Sometimes NxM result might be even requirement then subquery won’t fulfil it.

    Query (subquery version) fails when subquery returns more than one row or more than one column (that’s why other answers limits returned rows in subquery to one by top or max which is not always sufficient). cross join will do it without any problems, it’s is more elastic.

    Tests done on tables:

    create table species ( -- 9999 rows
        id int identity(1, 1), -- unique
        scientific varchar(50), -- not unique
        english varchar(50) -- unique
    )
    
    create table genus ( -- 2233 rows
        id int identity(1, 1), -- unique
        name varchar(50) -- unique
    )
    

    Before each query I’ve run:

    dbcc freeproccache
    dbcc dropcleanbuffers
    

    Query:

    select s.*, g.name
    from species s
    cross join genus g
    where g.name = 'Pinaroloxias'
    

    Execution plan:

    execution plan cross join

    Stats:

    SQL Server parse and compile time: 
       CPU time = 0 ms, elapsed time = 5 ms.
    
    (9999 row(s) affected)
    Table 'species'. Scan count 1, logical reads 79, physical reads 0, read-ahead reads 79, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
    Table 'genus'. Scan count 1, logical reads 12, physical reads 11, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
    
    (4 row(s) affected)
    
    SQL Server Execution Times:
       CPU time = 46 ms,  elapsed time = 224 ms.
    

    Query:

    select s.*, (select g.name from genus g where g.name = 'Pinaroloxias')
    from species s
    

    Execution plan:

    execution plan subquery

    Stats:

    SQL Server parse and compile time: 
       CPU time = 0 ms, elapsed time = 5 ms.
    
    (9999 row(s) affected)
    Table 'Worktable'. Scan count 1, logical reads 0, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
    Table 'genus'. Scan count 1, logical reads 12, physical reads 11, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
    Table 'species'. Scan count 1, logical reads 79, physical reads 0, read-ahead reads 79, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
    
    (8 row(s) affected)
    
    SQL Server Execution Times:
       CPU time = 31 ms,  elapsed time = 224 ms.
    

    Query:

    select s.*, (select max(g.name) from genus g where g.name = 'Pinaroloxias')
    from species s
    

    Execution plan:

    execution plan subquery with max

    Stats:

    SQL Server parse and compile time: 
       CPU time = 0 ms, elapsed time = 31 ms.
    
    (9999 row(s) affected)
    Table 'species'. Scan count 1, logical reads 79, physical reads 0, read-ahead reads 79, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
    Table 'genus'. Scan count 1, logical reads 12, physical reads 11, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
    
    (6 row(s) affected)
    
    SQL Server Execution Times:
       CPU time = 0 ms,  elapsed time = 229 ms.
    

    The test would be better if I had done it many times and calculated the average but I had no time for that.

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

Sidebar

Related Questions

I have a text area in my form which accepts all possible characters from
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I am currently running into a problem where an element is coming back from
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I need to clean up various Word 'smart' characters in user input, including but
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out

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.