Solved

SQL - Select From Left join & where

Posted on 2011-02-14
7
366 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]
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
Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

 
LVL 40

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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

More Fun with XML and MySQL – Parsing Delimited String with a Single SQL Statement Are you ready for another of my SQL tidbits?  Hopefully so, as in this adventure, I will be covering a topic that comes up a lot which is parsing a comma (or other…
Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

911 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

22 Experts available now in Live!

Get 1:1 Help Now