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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.