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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T08:00:20+00:00 2026-06-10T08:00:20+00:00

I have table (script below): use master go — — if db_id ( ‘CrossApplyDemo’

  • 0

I have table (script below):

use master
go

--
--
if db_id ( 'CrossApplyDemo' ) is not null
drop database CrossApplyDemo
go
create database CrossApplyDemo
go

use CrossApplyDemo
go

--
if object_id ( 'dbo.Countries', 'U' ) is not null
drop table dbo.Countries
go
create table dbo.Countries ( CountryID int, Country nvarchar(255) )
go

--
insert into dbo.Countries ( CountryID, Country )
values ( 1, N'Russia' ), ( 2, N'USA' ), ( 3, N'Germany' )
     , ( 4, N'France' ), ( 5, N'Italy' ), ( 6, N'Spain' )
go

--
if object_id ( 'dbo.Cities', 'U' ) is not null
drop table dbo.Cities
go
create table dbo.Cities ( CityID int, CountryID int, City nvarchar(255) )
go

--
insert into dbo.Cities ( CityID, CountryID, City )
values ( 1, 1, N'Moscow' ), ( 2, 1, N'St. Petersburg' ), ( 3, 1, N'Yekaterinburg' )
     , ( 4, 1, N'Novosibirsk' ), ( 5, 1, N'Samara' ), ( 6, 2, N'Chicago' )
     , ( 7, 2, N'Washington' ), ( 8, 2, N'Atlanta' ), ( 9, 3, N'Berlin' )
     , ( 10, 3, N'Munich' ), ( 11, 3, N'Hamburg' ), ( 12, 3, N'Bremen' )
     , ( 13, 4, N'Paris' ), ( 14, 4, N'Lyon' ), ( 15, 5, N'Milan' )
go

I select cities groupping by countries, i can perform queries using two approaches:

-- using join:
select *
from CrossApplyDemo.dbo.Countries as countries
inner join CrossApplyDemo.dbo.Cities as cities on cities.CountryID = countries.CountryID
-- using apply
select *
from CrossApplyDemo.dbo.Countries as countries
cross apply (select * from CrossApplyDemo.dbo.Cities as cities where cities.CountryID = countries.CountryID) as c;

Is where any query without “cross apply” which can return the same result as “apply query” below? :

select *
from CrossApplyDemo.dbo.Countries as countries
cross apply (select top(3) * from CrossApplyDemo.dbo.Cities as cities where cities.CountryID = countries.CountryID) as c;

the query:

select top(3) *
from CrossApplyDemo.dbo.Countries as countries
inner join CrossApplyDemo.dbo.Cities as cities on cities.CountryID = countries.CountryID

not work

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

    Yes.

    select
        CountryID, Country, CityID, CountryID, City
    from
    (
    
    select Cities.*,
        Country,
        ROW_NUMBER() over (partition by cities.countryId order by cityid) rn
    
    from 
    cities
        inner join countries on cities.CountryID= countries.CountryID
    ) v
    where rn<=3
    and CountryID=1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following script to create a table: -- Create State table. DROP
I have a script that drops a load of tables using DROP TABLE IF
I have a PHP script that inserts data into a mysql database. The table
I have simple table creating script in Postgres 9.1. I need it to create
Say I have written a Create Table script in a query window and run
I have a table cell (td) that triggers a script when clicked. I have
I have a script that reads a list of addresses from a table and
I have a php script that backup my table in .sql format and I
I have a Perl script that takes text values from a MySQL table and
I have a fasterCSV rake script but it only imports to 1 table. I

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.