Search code examples
mysqldateselectjoinsqlfiddle

Selecting specific rows based on data from other table


I have the flowing tables:

See fiddle: http://sqlfiddle.com/#!2/c1c2f/1

I'm struggling to find a way to

select software.name, systems.pc(or software.pc), systems.user

only for the rows were the software.date field matches the systems.time field meaning that fields


Solution

  • You need a JOIN, like this:

    SELECT software.name, software.pc, systems.pc, systems.user
    FROM software
    JOIN systems
    ON software.date = systems.time AND software.pc = systems.pc;
    

    Fiddle: http://sqlfiddle.com/#!2/c1c2f/34/0