我收到以下错误:
ERROR 1052 (23000) at line 1: Column 'id' in where clause is ambiguous
数据库:MySQL 5.5.30(包含架构中的所有表和列)
SELECT cam.id, cam.name AS campaign_name, cam.subdomain, usr.id AS user_id, usr.email, usr.display_name AS user_display_name
FROM campaigns AS cam
INNER JOIN users AS usr
ON usr.id = cam.user_id
WHERE cam.state=2
AND (usr.email = "hello@me.com")
AND cam.id IN (105793,107290,106048,107107,15097,108580,107394,107560,108942,107670,107925,107056,106089,30931,106864,45868,107625,106878,106417,88858,106065,106758,3282,103372,4449,108440,107311,106239,105857,110712,110243,105939,107001,105950,107124,105882,106139,107548,432,107466,105942,107115,51342,106437,106482,107192,105867,106993,107667,103769,108745,49924,105763,105935,99140,107402,20637,21155,105788,89963,106421,70124,12304,4748,107015,109758,103145,107590,106968,110692,26533,24993,33660,107398,34584,49597,107518,108878,107036,107668,105410,107060,106135,29205,106026,79254,19132,108692,107572,106978,93445,105678,107386,105866,106449,112104,id,312012,308555,323625,314793,321195,310245,291101,306016,179787,308224,290484,318154,318116,70226,313982,311419,71197,320725,271482,317257,331048,316765,75626,76321,329973,314034,313681,313850,306487,317443,83760,314759,339990,323732,306470,330480,89979,304814,91365,92541,316037,315131,116866,315323,111116,316067,316164,197902,129172,319690,141828,313517,315838,317608,310268,315096,309004,290518,319317,316349,316365,336052,183055,321936,318115,316950,330521,331975,324045,315540,201025,315770,321558,317962,200887,317500,328721,320403,311716,315812,318661,344680,315843,317483,317588,258656,317936,329850,245554,344785,314865,316722,329550,314332,316360,291604,341029,261118,264395,335387,330797,315403,276508,275586,275717,281996,276689,276709,290611,276957,277804,278480,279042,279381,344612,317507,280753,329926,281838,304604,311660,287452,317401,292158,305459,287031,312338,330015,295562,343920,289372,289377,328036,313204,322422,289641,289457,289486,291896,289453,298416,316894,289474,289476,289491,289566,289586,289599,289672,289677,328909,293962,289720,289754,289745,289774,293484,330235,289898,303233,290083,290120,290242,290327,290359,290399,290438,290475,290555,290628,290872,291214,291418,291333,291652,291779,313939,292236,292340,314508,293046,293376,293185,342259,293263,293515,293600,294511,295262,293957,294073,317855,294397,311490,294691,298226,294861,295088,295145,302131,313369,296434,315662,310084,322252,297288,297360,297432,298203,298794,299262,333157,305860,304484,304422,304462,304649,327116,304487,304504,318641,304528,304574,312829,304617,304668,304632,304924,304658,318170,304651,304762,304771,304770,304806,305019,304831,305281,304892,304941,304990,305008,305040,305041,337272,305048,305107,305126,309925,305195,305256,305284,305334,305294,305327,305342,305405,305521,306679,305520,305546,305595,305650,305659,305732,305712,305779,305798,305819,305838,305873,319122,307946,305937,310949,306243,306112,306113,306120,306140,306142,322700,306197,307466,306263,313766,318790,306303,306344,306346,306374,306407,306406,306415,306445,306465,306486,306510,309524,341418,306687,309657,306759,308941,306751,306779,306756,306778,307202,308147,329657,330603,306859,320503,306849,306870,331402,306863,306928,306880,306894,306906,306918,306936,307479,306962,306970,306968,306982,306986,307001,307005,307008,309223,307007,307011,307061,307062,307092,308177,332228,307478,307127,328246,307161,337299,330104,307791,307412,307424,328480,307430,307447,307454,307473,307480,307512,307493,314340,307542,307526,307527,307545,307589,307623,336402,307652,307659,333206,307666,319975,307674,313887,310200,307713,307761,307771,309273,307817,307823,310259,307878,307889,312913,307976,308013,308021,308120,308174,308182,319795,308272,308290,333845,324412,308441,308450,308468,308479,308566,308525,308544,308561,308598,308616,308617,318255,308648,308651,308657,308663,308668,308671,335094,308680,311769,308872,334045,308717,308739,308788,308804,312547,308819,308827,308911,308904,309543,309015,309021,309052,309220,309079,309099,309163,309179,327520,309243,309236,314363,309263,309279,309285,309314,309364,309406,309457,309478,309495,309552,309952,309588,309613,309636,309638,309650,313116,310919,309734,314296,309811,309849,309882,325089,310459,338535,309931,309940,310023,310002,310007,310030,310032,318779,310081,310118,319304,310120,325833,310144,310145,310151,310204,310210,310278,329000,322690,310323,310383,317187,310442,310447,310451,310461,310488,311128,310545,310567,310566,310575,310597,310600,311042,310636,310661,310659,310666,310680,310707,310691,310709,310720,310722,310723,310725,314488,310736,310754,310762,310763,320101,310796,310894,310947,310953,312134,311039,311257,311200,311139,311152,311156,311164,311215,311218,311233,314467,311307,311313,311322,311333,311358,311379,311446,311448,315437,311530,311550,311570,311637,311638,311683,311702,311663,311699,311712,311739,311752,311808,311822,311826,342130,311881,311898,311907,325253,312032,312047,312050,312078,312098,313206,312165,312170,312188,312240,312241,312257,316515,312261,312302,312756,312340,312388,312459,322362,312453,312492,312501,312512,312568,312521,312543,314688,312584,312588,325194,312597,330651,312712,312821,312768,312809,325199,312857,312866,312871,312887,312891,312892,312906,312919,312928,312952,342782,312951,312968,312966,313020,313028,313057,313058,313062,313064,313071,327699,313471,313123,313193,324221,313270,313298,313300,313321,313354,313401,313408,314164,313479,344095,313554,314879,313582,313579,314849,313619,313620,313647,313674,313697,313715,313718,313721,313725,315051,313776,318773,313811,313857,333559,313843,313883,313920,313936,313974,320242,314247,315426,314032,314082,314085,314108,314112,314141,315142,314173,314229,314243,314664,314359,314365,314372,314400,314376,314395,314466,314468,314476,315731,314491,314492,316501,314875,314551,314562,314589,314614,314629,314651,314675,314652,314656,314751,315509,314770,314771,314834,314806,314860,314874,314916,315030,314923,314975,315021,315018,315019,315037,320761,337287,315047,315063,315139,315087,315102,315122,326907,315194,315200,315224,315232,315239,315252,315258,315318,315347,315357,315380,315388,338468,315395,315414,315420,316572,315441,335308,315453,315486,315488,317629,315565,315664,315686,315691,315707,315775,317867,315829,318320,315895,316394,315899,316178,315902,326518,316286,316030,316012,326614,316047,316062,316078,316128,316633,316151,316182,316189,319659,316822,316231,316238,316256,316267,321759,316282,317917,316372,316379,316402,316428,328069,316775,316457,316490,316467,316543,316586,316602,316616,316617,316646,320300,316685,316965,316739,328530,316790,316795,327353,316823,321203,316841,339982,330937,317245,316860,316881,316887,316892,316925,325234,342990,320909,331646,330988,320580,327576,317465,317054,323357,317149,317201,317239,317235,317243,319624,317355,317290,318297,317294,322359,320591,319131,317360,317410,317674,317533,317482,332117,317522,317556,317590,317613,317643,317673,319865,324529,317801,317866,323277,318733,317905,317909,318010,318056,318223,318146,318196,318208,318245,318262,318858,320332,322855,335628,321932,323584,325517,327285,326636,329112,327394,329130,328687,328625)
ORDER BY cam.id ASC
当我剥离“AND cam.id IN ()”部分时,它会执行。
为什么会发生这种情况,尽管我已经完全限定了该列(即“cam.id”而不是“id”)?
我尝试过的事情:
- 删除“AND cam.id”子句 --> 语句执行没有错误
- 使用“campaigns.id”而不是“cam.id”-> 错误 1054 /“where 子句中的未知列”
- 更新它可以工作,如果我只有几个(比如 5 个)项目
IN clause