SQL join question

Peter Haworth pete at lcsql.com
Fri May 15 14:07:23 EDT 2015


Hi Bob,
Something not right there.  A LEFT JOIN should return all entries from the
left table, presumably devices in your example, whether or not there are
any matching entries in the other side of the join (accessories).

One possibility is that your SELECT statement should name the devices table
in the FROM clause and the JOIN should name the accessories table.  if the
SELECT names the accessories table and the JOIN goes to the devices table,
that would give the result you're seeing.

Hard to diagnose further without seeing your SELECT statement.

Pete
lcSQL Software <http://www.lcsql.com>
Home of lcStackBrowser <http://www.lcsql.com/lcstackbrowser.html> and
SQLiteAdmin <http://www.lcsql.com/sqliteadmin.html>

On Fri, May 15, 2015 at 10:57 AM, Bob Sneidar <bobsneidar at iotecdigital.com>
wrote:

> Hi all.
>
> I am just now learning SQL joins, and I have run across an interesting
> caveat. It may be how sqlYoga is working or it may be how joins work. I
> have two tables, devices and accessories. This is a one to many
> relationship. I set up the join as a left join on devices.deviceid =
> accessories.deviceid. Not all devices have associated accessory records.
>
> The problem is, instead of getting a record with every device in
> inventory, whether or not it has accessories, I am *ONLY* getting devices
> with associated accessories. Is this the normal behavior of joins? If not,
> how would I structure the join so that I got blank accessory columns for
> devices without accessories?
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>



More information about the use-livecode mailing list