php - finding latest entry in DB and all other before it in a different table -


this easy thing in theory havent got clue how it. need method find latest timestamp/entry in table called 'answers' in mysql db. , upon finding this, find ip's stored in table called 'ip' timestamp occur before said mention 'answers' entry.

any ideas? im guessing if() function best way?

edit: table structure 'ip' exists.

create table if not exists `votes` ( `id` int(250) not null auto_increment, `ip` varchar(30) not null, `answer_id` int(250) not null, `poll_id` int(250) not null, `timestamp` int(250) not null, primary key (`id`) ) engine=myisam default charset=latin1 auto_increment=2 ; 

and table 'answers' live

create table if not exists `answers` ( `id` int(250) not null auto_increment, `poll_id` int(250) not null, `answer` varchar(250) not null, primary key (`id`) ) engine=myisam default charset=latin1 auto_increment=3 ; 

surely can pure database solution doesn't need doing in php?

assuming tables in same database, both have timestamp column , named answers , votes respectively, then:

select * votes v v.timestamp <= (select max(a.timestamp) answers a) 

edit : replaced names according schema, don't see timestamp column in answers?


Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -