Mysql only select records present in other table -


i've got 2 tables:

loggingtypes id name  logfiles id type_id (linked loggintypes.id) client_ip time logcontent 

i quite new mysql, looking query selects * loggingtypes if there logs linked it.

with "select * loggingtypes order name" everything, how select rows have logs linked it?

is

select  distinct logging_types.id, loggingtypes.name  logging, logging_types  logging.type_id = loggingtypes.id 

the best way go?

as far can tell, query right.

one alternative use join:

select distinct      lt.id, lt.name      logging_types lt     inner join logging l on lt.id = l.type_id 

Comments

Popular posts from this blog

node.js - Bad Request - node js ajax post -

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -