Solved

sql query help

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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

777 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