View Full Version : Selecting only one field at a time where multiple rows have the same value
04-24-2009, 11:03 PM
Newbie here, so if this doesn't make sense I'm sorry. I'm creating a comments area on a page where users can comment on content. I would like to preview a comment before it is posted, so I've created a page where a comment is posted before going to the final database where it is selected from to post onto the final page. I've added a field with a boolean value, so if false, it hasn't been viewd before. If I select all fields that hold false, how can I pull them out one at a time instead of all at once?
04-24-2009, 11:18 PM
When you say 'getting all the fields' do you mean using the mysql query :
SELECT * FROM table_name
if so then all you need to do is change your mysql query to :
SELECT field_name FROM table_name
04-24-2009, 11:38 PM
Thanks for the quick reply. I have that query, but what I'm saying is I have multiple fields with the same value and I only want to pull out one at a time.
04-25-2009, 12:15 AM
SELECT * FROM rawcomments
WHERE reviewedflag = false
ORDER BY whenposted
LIMIT 1 in MySQL means "only get one"
The ORDER BY will ensure you get the oldest comment, assuming you record the date and time when a comment was posted.
04-25-2009, 12:17 AM
Awesome. That works great. Thanks a ton.
04-25-2009, 12:19 AM
By the way, you do *NOT* have "multiple fields with the same value."
That implies to a SQL user that you have two or more fields (also known as columns) IN THE SAME RECORD that have the same value.
What you have is multiple RECORDS where the value of the SAME FIELD is duplicated.
It was your terminology that confused Killermud, I would guess.
Powered by vBulletin® Version 4.2.2 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.