Solved

SQL - Select From Left join & where

Posted on 2011-02-14
7
365 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 142

Expert Comment

by:Guy Hengel [angelIII / a3]
Comment Utility
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
Comment Utility
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
Comment Utility
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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 40

Expert Comment

by:Sharath
Comment Utility
>> 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
Comment Utility
>> 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
Comment Utility
thanks
0
 
LVL 23

Expert Comment

by:Rajkumar Gs
Comment Utility
Glad to help you
Raj
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Fore-Foreword Today (2016) Maxmind has a new approach to the distribution of its data sets.  This article may be obsolete.  Instead of using the examples here, have a look at the MaxMind API (https://www.maxmind.com/en/geolite2-developer-package). …
I use MySQL for many of my development projects in a Windows environment. To manage my databases (and perform queries) for years I used a tool called MySQL administrator.  This tool has since been replaced by MySQL Workbench. So I decided to m…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

744 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now