|Related to : Laravel blade multiple select. How to select records in the pivot table?|
|Need to rewrite query to select multiple records in secondary table|
Remove the GROUP BY and it will return all of the comments.
FROM people AS p
LEFT JOIN comments AS tc ON (tc.pID = p.id)
WHERE p.projID = $project_id
|SQL query to select records which must have all values from another table as substring|
One approach is:
from Rules r
join Input i
on r.RuleValue like '%' + i.RulePart + '%'
group by r.RuleValue
having count(distinct i.RulePart) = 3 -- or (select count(*) from
More elegant way is using NOT EXISTS to represent for ALL
from Rules r
where not exists
from Input i
where r.RuleValue n
|SQL SELECT to multiple table|
You could join the membre table to your original query? This would be
done in a similar way to the Inner join you used in your first query.
You could either use an inner join again or a left join may be
appropriate. Using a second join means you would not need to do two
For more information about SQL joins, you may find
http://dev.mysql.com/doc/refman/5.0/en/join.html useful. It
|Laravel get data from pivot table|
I'm, battling insomnia and not functioning at 100%, but you should be
able to get away with $user->operator->id based on what I'm
interpreting your models to be (it looks like you had a typo when you
copied them into the question).
If that doesn't work, you might want to check out the "Dynamic
Properties" section in the Eloquent docs for more info, if you haven't
|SQL Select only records with no duplicates|
I am guessing that by "duplicate" you mean that the value in [Column
0] only appears once.
You can do this with window functions:
from (select t.*, count(*) over (partition by [Column 0]) as cnt
from tab1 t
where cnt = 1;