简体   繁体   中英

Select Records from INNER JOINed table only ONCE

$Sql = "SELECT * FROM Table1 INNER JOIN Table2 ON Table1.Schedule_ID = Table2.SheduleId WHERE Table1.ID = '$id' AND Table2.Scheduled = '1'";

The rows in Table1 are only selected if Table1.Schedule_ID has the same value as a record in Table2.SheduleId . For TWO values in Table1 it selects the same row TWICE from Table2 . I'd like to avoid that and make each row from Table2 SELECT -able only once.

I tried SELECT DISTINCT * FROM Table1 but to no avail.

Please provide suggestions.

If I understood well please try this modification:

$Sql = "SELECT DISTINCT Table2.* FROM Table1 INNER JOIN Table2 ON Table1.Schedule_ID = Table2.SheduleId WHERE Table1.ID = '$id' AND Table2.Scheduled = '1'";

I hope it will help in any way.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM