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

x
?
Solved

SQL - Select From Left join & where

Posted on 2011-02-14
7
Medium Priority
?
370 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
[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
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
Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

 
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

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

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

Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
When table data gets too large to manage or queries take too long to execute the solution is often to buy bigger hardware or assign more CPUs and memory resources to the machine to solve the problem. However, the best, cheapest and most effective so…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
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

721 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