Instead of having ten tables like that, which will be ugly for your program once you want to add another search engine, have two tables, one for the "visit", and one for the "search_engine", like that:
-- SQL code: CREATE TABLE IF NOT EXISTS visit ( id int auto_increment not null, engine_id int, ip int, date date, primary key (id) ); CREATE TABLE IF NOT EXISTS search_engine ( id int auto_increment not null, useragent int, name char(256), homepage char(256) );
You then add, for every visit, a new row into the visit table, and put in the number of the search engine from the search_engine table. Having all the data in one place makes then selecting the last 10 engines very easy:
select distinct search_engine.id from search_engine inner join visit on search_engine.id = visit.engine_id order by visit.date desc limit 10;
I'm not exactly sure if you want to show the last 10 visiting search engines, or if you want to show the search engines, if any, that made the ten last hits. Getting the search engine(s) for the ten last hits is harder:
select distinct search_engine.id from search_engine inner join (select visit.id from visit order by visit.date desc limi +t 10);
In reply to Re: newbie table structure
by Corion
in thread newbie table structure
by coldfingertips
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |