Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

SQL - Select From Left join & where

Posted on 2011-02-14
7
Medium Priority
?
371 Views
Last Modified: 2012-05-11
hi,
im trying to select some data from 2 tables, where i left join the info in table2, where t2.name = "x"

so ive got the following but it just doesnt work?

select t1.ent, t2.priv
from file.csv t1
left join file2.csv t2
on t1.ent = t2.ent
where t2.app = 'x'

it does all work until i add in the final where clause and then the results are empty
but i know that t2.app = "x" does exist
0
Comment
Question by:jamiepryer
7 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 34889404
this shall work:
select t1.ent, t2.priv
from file.csv t1
left join file2.csv t2
on t1.ent = t2.ent
AND t2.app = 'x'

Open in new window

0
 
LVL 23

Expert Comment

by:Rajkumar Gs
ID: 34889412
What is the result of this query ?
select t1.ent, t2.priv
from file2.csv t2
left join file.csv t1
on t1.ent = t2.ent
where t2.app = 'x'
0
 

Author Comment

by:jamiepryer
ID: 34904192
Angel - didn't work with the and

Raj - gives null resuts as I think the where is being applied to the whole query, not just the above join statement
0
Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

 
LVL 41

Expert Comment

by:Sharath
ID: 34904252
>> Angel - didn't work with the and

What do you mean by not working? Can you post the result of that query and expected result?
0
 
LVL 23

Accepted Solution

by:
Rajkumar Gs earned 2000 total points
ID: 34990671
>> but i know that t2.app = "x" does exist
Even if 'x' exists, you have used JOIN between the two tables. So both should have the same related data. Then only the result gets the 'x' related data.

Just double-check the existance of 'x' data using this query
SELECT  *
FROM    file2.csv
WHERE   app = 'x' 

Open in new window


If YES, continue with this query to check whether the related records of 'x' data is in other table
SELECT  *
FROM    file.csv
WHERE   ent IN ( SELECT ent
                 FROM   file2.csv
                 WHERE  app = 'x' )

Open in new window


Please let us know
Raj



0
 

Author Closing Comment

by:jamiepryer
ID: 35745692
thanks
0
 
LVL 23

Expert Comment

by:Rajkumar Gs
ID: 35746002
Glad to help you
Raj
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
Backups and Disaster RecoveryIn this post, we’ll look at strategies for backups and disaster recovery.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses
Course of the Month11 days, 21 hours left to enroll

916 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