I guess the USING syntax is where the joining column names match in both tables.

Another way is to use the explicit: JOIN othertable ON condition

SELECT L.lesson_id, L.title, L.total_time, P.wasPurchased
FROM lessons L JOIN purchase_data P ON P.group_id = L.group_id
WHERE L.lesson_id>=$id AND L.group_id>=$group_id
ORDER BY L.group_id, L.lesson_id LIMIT 0,2

Btw, be careful where you get your $id and $group_id variable content
from. If you are embedding these in a string (e.g. in a Perl script)
then you should check these are numeric before you use them. Otherwise
this is how SQL injection attacks happen, e.g. I might submit a
malicious ID containing SQL commands which could screw up your
database.

Cheers,
Larry


On 8 February 2012 03:05, Igor Tandetnik <itandet...@mvps.org> wrote:
> On 2/7/2012 1:55 PM, E3 wrote:
>>
>>
>> Hi, sorry for the easy question.
>>
>> I have a table "lessons" I query this way:
>>
>> "SELECT lesson_id,title,total_time FROM lessons WHERE lesson_id>=$id AND
>> group_id>=$group_id ORDER BY group_id,lesson_id LIMIT 0,2"
>>
>> lesson_id is primary and autoincrement.
>>
>> This query perfectly works and it does exactly what is supposed to do.
>>
>> Then I have another table ('purchase_data'), with a column 'group_id'
>> (related to the 'group_id' of 'lessons' table) and a "wasPurchased" field
>> that can take boolean values (0 or 1: 1 meaning the related item has been
>> purchased).
>>
>> Now, I want to modify that query to extract if the lesson has been
>> purchased.
>
>
> SELECT lesson_id,title,total_time, wasPurchased
> FROM lessons join purchase_data using (group_id)
>
> WHERE lesson_id>=$id AND group_id>=$group_id
> ORDER BY group_id,lesson_id LIMIT 0,2
>
> --
> Igor Tandetnik
>
>
> _______________________________________________
> sqlite-users mailing list
> sqlite-users@sqlite.org
> http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to