Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
232 views
in Technique[技术] by (71.8m points)

mysql - I have written query to sort name starting with S and V in give database , error coming up is below

select * from cricket_1111 , cricket_999 
where first_name LIKE "s%v" 
LIMIT 0, 1000   

Error Code: 1052. Column 'first_name' in where clause is ambiguous 0.000 sec


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You have a first_name column in both tables, so you have to specify which table you want to use like

select * 
from cricket_1111 , cricket_999 
where cricket_1111.first_name LIKE "s%v" 
LIMIT 0, 1000   

It would also be very productive if you took a look at the JOIN syntax rather than using from cricket_1111 , cricket_999

Something like

select * 
from cricket_1111 c1
    JOIN cricket_999 c9 on c9.link_column = c1.link_column
where c_1.first_name LIKE "s%v" 
LIMIT 0, 1000 
ORDER BY c_1.first_name

Also a limit clause without a sort ORDER BY can be very unpredictabe


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...