lundi 26 janvier 2015

How do I improve this SQL query?

It's been awhile since I worked with SQL, and I can't remember the best way get data from linked tables. What is the best way to get data from tables Cat and Bat?



Apple
---------
batId
catId

Bat
---------
id
batField1
batField2
batField3

Cat
---------
id
catField1
catField2
catField3


I'm trying to get batField1, batField3, and catField1. This is my current query



SELECT b.batField1, b.batField3, c.catField1
FROM Apple AS a, Bat as b, Cat as c
WHERE a.batId = b.id OR a.catId = c.id;

Aucun commentaire:

Enregistrer un commentaire