Solved

SQL query help

Posted on 2014-12-10
2
239 Views
Last Modified: 2014-12-10
Hello there,

I have this query and I get this error when I run it
Invalid column name 'province'.

 SELECT * FROM (SELECT *, ROW_NUMBER() OVER (ORDER BY province) AS rowID FROM (SELECT TOP 100 PERCENT  
			province.capital,
    province.code,
    province.telcode,
    province.taxcode,
    county.countyname as county,
    district.districtname as district,
    zone.alternateName as zone,
    neighbourhood.alternateName as neigbhour,
    city.cityname as city,
    city.fdocode 
			 FROM 
				province
				JOIN county ON province.Id = county.provinceId
				JOIN district ON district.countyId = county.Id
				JOIN city ON city.districtId = district.Id
				JOIN zone ON zone.cityId = city.Id
				JOIN neighbourhood ON neighbourhood.zoneId = zone.Id
				JOIN customer ON customer.neighbourhoodId = neighbourhood.Id
			 WHERE ('1'='1')) x) y WHERE y.rowID BETWEEN 1 AND 75

Open in new window

0
Comment
Question by:zolf
2 Comments
 
LVL 47

Accepted Solution

by:
Vitor Montalvão earned 300 total points
ID: 40490842
Looks like province is a table and you are using it in the ORDER BY clause.
Verify the line SELECT *, ROW_NUMBER() OVER (ORDER BY province) AS rowID and check which column should be used in the ORDER BY clause
0
 
LVL 142

Assisted Solution

by:Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3] earned 200 total points
ID: 40490848
province is a table name, in the first place, so if that (or another table) also has a column name province, you need to write this in the query for the column province.province
which also brings up this article I wrote: use aliases in your queries:
http://www.experts-exchange.com/Database/Miscellaneous/A_11135-Why-should-I-use-aliases-in-my-queries.html
0

Featured Post

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
sql how to count case when 4 17
New to SSRS, extremely slow running report. 8 20
SQL Query Help Top 1 and Distinct? 6 26
awk and Pythagoras? 5 8
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.​
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

809 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