当前位置: 动力学知识库 > 问答 > 编程问答 >

sql - mysql select statement is not working

问题描述:

I don't seem to be able to get my SELECT statement to work.

This is the table:

CREATE TABLE clients(

user_id MEDIUMINT UNSIGNED NOT NULL AUTO_INCREMENT,

email VARCHAR (70) NOT NULL,

mobile_number int(11) NOT NULL,

UNIQUE KEY (email)

);

The Select Query

SELECT user_id FROM clients WHERE email='[email protected]';

Whenever I try using this SELECT statement from mysqlADMIN it returns null; this happens even when I enter an email address that I know is in the database.

I would really appreciate some advice on where I am going wrong.

网友答案:

Try the statement without the "WHERE" clause. If it returns the entire table you have narrowed it down to an error in your "email" string.

If it returns nothing and you know there is data in this table then check your connection string and make sure you are using the correct DB.

网友答案:

I think there is some error in your SQL create statement. You should make the unique key to which you have applied auto increment. In this case the database will give an error.

Please try the following creation statement

CREATE TABLE clients(
user_id MEDIUMINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
email VARCHAR (70) NOT NULL,
mobile_number int(11) NOT NULL
); 
分享给朋友:
您可能感兴趣的文章:
随机阅读: