Solved

SQL - Select From Left join & where

Posted on 2011-02-14
7
368 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
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 
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 500 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

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

Suggested Solutions

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Foreword This article was written many years ago, in the days when PHP supported the MySQL extension (http://php.net/manual/en/function.mysql-connect.php).  Today (http://php.net/manual/en/migration70.removed-exts-sapis.php) you would not use MySQL…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

737 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