Solved

help needed with Microsoft SQL Server syntax

Posted on 2011-03-14
5
192 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
  • 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

759 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now