Jump to content

why does this print twice?


pavankat

Recommended Posts

for some reason this query returns the same row twice. How do i do make it not do that? I can't do DISTINCT .

 

because i'm grabbing this from a table where the user might have actually submitted the same thing twice on purpose.

 

Help me please. I've been looking at this for awhile. Also, I know I haven't protected it from sql injection - i'm going to do that after I pull my hair out.

 

SELECT  `NDB_No` ,  `Shrt_Desc` ,  `Vit_K_(mcg)` ,  `Energ_Kcal` ,  `FA_Sat_(g)` ,  `Sugar_Tot_(g)` ,  `Sodium_(mg)` ,  `GmWt_Desc1` ,  `calendar_month` , `calendar_day` ,  `calendar_year` ,  `servings`

FROM  `measu_one_common`

LEFT JOIN users_calendar ON measu_one_common.NDB_No = users_calendar.food_id

WHERE users_calendar.user_id =10 &&1 = calendar_day &&4 = calendar_month &&2012 = calendar_year

ORDER BY users_calendar.id

Link to comment
https://forums.phpfreaks.com/topic/260789-why-does-this-print-twice/
Share on other sites

That duplicated row probably has two matching rows in the other table (it's hard to tell which table is which in what you've posted). Example:

table1     table2

id | one   id | two
---+----   ---+----
1 | abc    1 | JKL
            1 | XYZ


SELECT table1.* FROM table1 JOIN table2 ON table1.id = table2.id

(table1)  (table2 which you can't see)
id | one  | id | two
---+----  +----+----
1 | abc  |  1 | JKL
1 | abc  |  1 | XYZ

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.