Solved

sql query help

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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

632 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