Another SQL question

Brian Yennie briany at qldlearning.com
Thu Feb 5 04:26:04 EST 2009


A simple join would work for this as well:

SELECT * FROM employees, departments WHERE employees.deptid =  
departments.deptid

As a bonus, this way you could easily pick what fields you wanted from  
each table. For example:

SELECT employees.id,employees.name,departments.name FROM employees,  
departments WHERE employees.deptid = departments.deptid


>
>> So using your method, my queries for a table of 25 employees with the
>> associated departments data would look something like this:
>>
>> -- employee data
>> put "SELECT employees.deptid FROM employees LIMIT 25" into
>> mEmployeeQuery
>>
>> -- department data
>> put "SELECT * FROM departments WHERE departments.deptid IN (" &
>> mEmployeeQuery & ")" into mDepartmentQuery
>
> Actually, Bob, you don't need to do two queries... you can do it in  
> one...
> also, you don't need to use LIMIT unless you specifically want less  
> records
> than what would normally be returned:
>
> SELECT * FROM departments WHERE departments.deptid IN (SELECT
> employees.deptid FROM employees)
>
> HTH,
>
> Ken Ray
> Sons of Thunder Software, Inc.
> Email: kray at sonsothunder.com
> Web Site: http://www.sonsothunder.com/



More information about the use-livecode mailing list