Take the 2-minute tour ×  I am building a url shortening /
redirect service and I'm a bit confused as to how I can best get
the data from two tables.  I have two tables like so:      Links
stores the link details and every time there is a redirect it's
logged in the redirects table as a single row for each redirect.
alias in links and url_string in redirects are the same. e.g.
Dw4 so the domain would be example.com/Dw4 - redirects to the
url field in links.  What I'm trying to achieve is to select
(and count) all redirects from the redirects table where the
url_string is same as alias and then where user_id is the same
as the logged-in user.  I am using Codeigniter.  So far I'm
trying to go for something like this
$query=$this->db->query("SELECT * " . "FROM links, redirects " .
"WHERE links.alias = redirects.url_string");  But i'm having no
look.  share|improve this question add comment  3 Answers  up
vote 1 down vote accepted  JOIN the two tables like so:  FROM
redirects r INNER JOIN links l ON r.url_s