pavankat Posted April 12, 2012 Share Posted April 12, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/260789-why-does-this-print-twice/ Share on other sites More sharing options...
requinix Posted April 12, 2012 Share Posted April 12, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/260789-why-does-this-print-twice/#findComment-1336635 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.