Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

sql query help

Posted on 2014-03-05
2
Medium Priority
?
232 Views
Last Modified: 2014-03-05
I need help with a sql query to select all columns where 2 state codes(PQ and QC) share the same city code.  I dont know the value of CityCode.  

All of these columns are in a table called tbCompanyCityMaster.

psuedo code below.

select * from
[tbCompanyCityMaster] 
where state in('QC','PQ') and CityCode (is same citycode for both 'QC' and 'PQ')  

Open in new window

0
Comment
Question by:hougie40
[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
2 Comments
 
LVL 2

Accepted Solution

by:
gdarcan earned 2000 total points
ID: 39907854
I assumed that you have an ID column which is a unique value for each rows.
select * from
[tbCompanyCityMaster] AS t1, [tbCompanyCityMaster] AS t2, 
where t1.ID<>t2.ID AND t1.state in('QC','PQ') and t2.state in('QC','PQ') and t1.CityCode=t2.CityCode   

Open in new window

0
 

Author Closing Comment

by:hougie40
ID: 39907869
thank you.
0

Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

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

Windocks is an independent port of Docker's open source to Windows.   This article introduces the use of SQL Server in containers, with integrated support of SQL Server database cloning.
When trying to connect from SSMS v17.x to a SQL Server Integration Services 2016 instance or previous version, you get the error “Connecting to the Integration Services service on the computer failed with the following error: 'The specified service …
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties

660 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