How do I select rows in a MySQL table by column/field value?
i have table called mes开发者_StackOverflowsages which has field called (emails) with type text . for example this field value is (email@domain.com , example@any.net . notme@yahoo.com , me@yahoo.com). and what i want when i am logged in with (me@yahoo.com) to display only messages that has value of (me@yahoo.com). how can it be done with mysql & php ?
SELECT * FROM MESSAGES WHERE EMAIL = 'me@yahoo.com';
but EMAIL should probably be indexed to avoid haveing to scan the whole table to find matching rows. And type TEXT
is probably unnecessary. Emails are not likely to be longer than 100 characters, so maybe set the type to VARCHAR(100)
or similar.
Or given that each user will have an id, it's perhaps better get them out by USER_ID (which should also be indexed):
SELECT * FROM MESSAGES WHERE USER_ID = ?;
where USER_ID is the ID in your USER table or equivalent.
精彩评论