Solved

sql query help

Posted on 2014-03-05
2
219 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 500 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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
MS SQL Server connect issues 4 37
Copy data to New Year 9 29
Can I skip a node in XML? 9 30
T-SQL to copy a database 37 66
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…
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Viewers will learn how the fundamental information of how to create a table.

740 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