Solved

help needed with Microsoft SQL Server syntax

Posted on 2011-03-14
5
196 Views
Last Modified: 2012-05-11

select 10 records from customers table for each city then inner join the customerid = customerid of all the tables that have those customerid and therefore returning the city, customerid, tablename and orderdate
0
Comment
Question by:Jimmy_inc
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 19

Expert Comment

by:Bhavesh Shah
ID: 35135458
0
 
LVL 19

Accepted Solution

by:
Bhavesh Shah earned 250 total points
ID: 35135459
Hi,


SELECT * FROM
(
SELECT Country, CustomerName, ROW_NUMBER() OVER(PARTITION BY Country ORDER BY Country DESC) AS 'Row'
from table1
)
WHERE Row <= 5



Just join table with above query
0
 
LVL 39

Assisted Solution

by:Pratima Pharande
Pratima Pharande earned 250 total points
ID: 35135463
try this


 select customerid , City from Customers
where (
   select count(*) from Customers as f
   where f.City  = Customers.City
) <= 5
0
 
LVL 19

Expert Comment

by:Bhavesh Shah
ID: 35135464
Hi Jimmy,

sorry...But you posted 3 Questions and all are interlinked so its advisable that post one question with all queries.

Thanks

Bhavesh
0
 

Author Comment

by:Jimmy_inc
ID: 35135508
Hi Brichsoft

Yeah your'e right -  Not enough coffee !

I should of only posted this question:

http://www.experts-exchange.com/Programming/Languages/SQL_Syntax/Q_26887029.html

Which others are interlinked too ?
0

Featured Post

Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In database programming, custom sort order seems to be necessary quite often, at least in my experience and time here at EE. Within the realm of custom sorting is the sorting of numbers and text independently (i.e., treating the numbers as number…
If you find yourself in this situation “I have used SELECT DISTINCT but I’m getting duplicates” then I'm sorry to say you are using the wrong SQL technique as it only does one thing which is: produces whole rows that are unique. If the results you a…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question