Reputation: 1313
I'm kind of struggling to limit only one table from the joined table.
I want to limit only the first table rosary_group_name. In the code below I limit both tables. Any idea?
$sql = "
SELECT e.id,
e.rosary,
e.group_name,
e.description,
u.group_id,
u.name,
u.decade,
u.intention,
u.datume
FROM `rosary_group_name` AS e
INNER JOIN `rosary_groups` AS u
ON e.id = u.group_id
ORDER BY e.id DESC $limit;
";
the variable $limit sets the number of rows to display from both tables. I want to apply $limit only to the first table.
Upvotes: 1
Views: 155
Reputation: 2917
You can try to use a sub-query for the first table, like
SELECT
e.*
u.group_id,
u.name,
u.decade,
u.intention,
u.datume
FROM (SELECT e.id, e.rosary, e.group_name, e.description, FROM `rosary_group_name` AS e $limit) AS e
INNER JOIN `rosary_groups` AS u
ON e.id = u.group_id
ORDER BY e.id DESC;
(not sure if the syntax is correct, sorry. but I hope you get an idea)
Upvotes: 2
Reputation: 992
Inner join will give you limited(matched rows) result. You should consider left join in order to get more result from the left side table
Upvotes: 1