Amir Rasti
Amir Rasti

Reputation: 768

Sql 'LEFT JOIN' two Tables that each Have 'Where' (not The join Condition )

this Left Join query works well:

SELECT * FROM `Articles`  
  LEFT JOIN `uploaders` ON 
   uploaders.username=Articles.Poster
   ORDER BY `DATE` ASC  LIMIT 5;

but when adding a 'Where' to the first table

 SELECT * FROM `Articles`  WHERE `Content` OR `Title` LIKE '%somthing'
  LEFT JOIN `uploaders` ON 
   uploaders.username=Articles.Poster
   ORDER BY `DATE` ASC  LIMIT 5;

I get syntax error. and I try to name the first result but still the same error

1:

SELECT * FROM `Articles`  WHERE `Content` OR `Title` LIKE '%somthing' AS art
  LEFT JOIN `uploaders` ON 
   uploaders.username=art.Poster
   ORDER BY `DATE` ASC  LIMIT 5;

2:

(SELECT * FROM `Articles`  WHERE `Content` OR `Title` LIKE '%somthing')Art
  LEFT JOIN `uploaders` ON 
   uploaders.username=Art.Poster
   ORDER BY `DATE` ASC  LIMIT 5;

What am I doing wrong? and if not this way how else can I do this?

Upvotes: 2

Views: 100

Answers (2)

Tudor Constantin
Tudor Constantin

Reputation: 26861

the where is after the join:

SELECT * FROM `Articles`  
  LEFT JOIN `uploaders` ON 
   uploaders.username=Articles.Poster
WHERE `Content` LIKE '%somthing' OR `Title` LIKE '%somthing'
   ORDER BY `DATE` ASC  LIMIT 5;

Upvotes: 1

Jon Ekiz
Jon Ekiz

Reputation: 1022

 SELECT * FROM `Articles` 
 LEFT JOIN `uploaders` ON 
   uploaders.username=Articles.Poster
 WHERE `Content` LIKE '%somthing' OR `Title` LIKE '%somthing'
 ORDER BY `DATE` ASC  LIMIT 5;

Upvotes: 3

Related Questions