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
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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.