arul
arul

Reputation: 300

Query not returning all the rows using inner join

SELECT table1.* , table2.Value 
FROM table1  
INNER JOIN  table2 
ON table1.id = table2.id 
WHERE table2.Label = "Currency"

This is the query. I need to return the values even if Label = currency does not exists. i.e., I need to return all rows of table1 with unique id. If table2 has currency then the currency value should be taken else empty value should return.

Upvotes: 0

Views: 524

Answers (3)

Lineesh P K
Lineesh P K

Reputation: 1

try this

SELECT table1.* , table2.Value FROM table1 left outer join table2 on table1.id = table2.id where table2.Label = "Currency" 

Upvotes: 0

Aziz Shaikh
Aziz Shaikh

Reputation: 16524

Try using OUTER JOIN like this:

SELECT table1.* , table2.Value 
FROM table1 
LEFT JOIN table2 
ON table1.id = table2.id 
AND table2.Label = "Currency"

Upvotes: 1

It sounds like you want something along these lines.

SELECT table1.* , table2.Value 
FROM table1 
left join table2 on table1.id = table2.id

I'm assuming that table2.value is the currency value you're talking about.

Edit your question, and paste CREATE TABLE statements for more and better answers.

Upvotes: 1

Related Questions