Is there a way to get the list of default groups (owners,contributors,members) of a room using dql in documentum 6.6
Besides
select builtin_groups from dmc_room where object_name ="MYROOM"
To list the room and there actual(owners and contributors only) groups use:-
select dg.group_name,dr.object_name from dm_group dg,dmc_room dr where group_name like 'room_%_%n%s' and dg.group_name IN dr.builtin_groups
select builtin_groups from dmc_room where object_name ="MYROOM"
Related
I am using DISTINCT ON to fetch latest rows from two joined tables. In my case a subscriber belongs to many categories and I need to fetch the latest category a subscriber belongs to. I've got it working in raw query but I need to recreate it using Eloquent.
SELECT DISTINCT ON (subscribers.id) subscribers.*,
subscriber_categories.*
FROM subscribers
LEFT JOIN subscriber_categories
ON subscribers.id = subscriber_categories.subscriber_id
ORDER BY subscribers.id, subscriber_categories.created_at DESC;
I have tried the following but not working. It's fetching all records from both tables:
Subscribers::
->join('subscriber_categories', 'subscribers.id', '=', 'subscriber_categories.subscriber_id')
->distinct('subscribers.id')
->latest('subscribers.id', subscriber_categories.created_at)
->paginate(7);
I finally ended up doing this. (totally abandoned DISTINCT ON):
$subscribers = \DB::table('subscribers AS t1')
->leftJoin(\DB::raw('(SELECT * FROM subscriber_categories A WHERE id in (SELECT MAX(id) FROM subscriber_categories group by subscriber_id)) AS t2'), function($join) {
$join->on('t1.id', '=', 't2.subscriber_id');
})->select('t1.id', 't1.s_phonenumber', 't1.timesubscribed', 't2.category')->latest('t1.created_at')->paginate(7);
I had the same issue and ended up writting a laravel extension to handle it. You can install it using composer, then it just works!
https://packagist.org/packages/datajoe/postgresql-distinct-on
This is what it would look like in your case:
Subscribers::
->join('subscriber_categories', 'subscribers.id', '=', 'subscriber_categories.subscriber_id')
->distinctOn('subscribers.id')
->latest('subscribers.id', subscriber_categories.created_at)
->paginate(7);
I have a table that a user placing bets on dUpdateTime.
DB Table :
My Query :
select * from tbet where iUserKey=53298
How do I create a query that would give me the latest dUpdateTime with iUserKey = 53298.
Using MAX aggregate function
SELECT MAX(dUpdateTime) FROM tbet WHERE iUserKey = 53298
Try this:
select * from tbet where iUserKey=53298 order by dUpdateTime desc limit 1
Use max aggregate function to get the latest
SELECT MAX(dUpdateTime) FROM tbet WHERE iUserKey=53298
i want to use full text search for create simple search engin.
for example when user search "Hamed Khatami",search engine fetch rows that have both word then
fetch rows that have one of them.
i created bottom query
select * from dbo.DownloadCenterFileLanguage
where CONTAINS(*,N' "*PC*" and "*Game*" ')
UNION
select * row from dbo.DownloadCenterFileLanguage
where CONTAINS(*,N' "*PC*" or "*Game*" ')
but it has a problem , it order result base on P.K.
Appreciate to help me.
Regards
after a day , i understand that my approach is wrong.
look at these codes
select * from dbo.DownloadCenterFileLanguage
inner join
CONTAINSTABLE (dbo.DownloadCenterFileLanguage,
*, 'ISABOUT ( "hamed" , "khatami" ,"*hamed*", "*khatami*"')') AS KEY_TBL
ON DownloadCenterFileLanguage.Id = KEY_TBL.[KEY]
with this approach everything work correctly
Best Regards
I try to resolve my problem since two days but I my code fails... Do you know how I can conert my sql query in doctrine ?
Sql query (the query work fine in phpmyadmin) :
SELECT distinct ms.ytId, ms.title FROM(
SELECT l.log_yt_id AS ytId, d.download_title AS title
FROM t_log l LEFT JOIN t_download d ON d.download_yt_id = l.log_yt_id WHERE l.log_creator = 'n' ORDER BY l.log_id DESC LIMIT 100
) ms
Thanks you all for your help !!
Best regards,
You can use doctrine dql.
First:
Check this page:
http://docs.doctrine-project.org/en/2.1/reference/dql-doctrine-query-language.html
Then remember:
If you want to use mysql functions like "RAND" etc. you have to define them in your config file after install a doctrine extensions bundle.
I have several sql queries that I simply want to fire at the database.
I am using hibernate throughout the whole application, so i would prefer to use hibernate to call this sql queries.
In the example below i want to get count + name, but cant figure out how to get that info when i use createSQLQuery().
I have seen workarounds where people only need to get out a single "count()" from the result, but in this case I am using count() + a column as ouput
SELECT count(*), a.name as count FROM user a
WHERE a.user_id IN (SELECT b.user_id FROM user b)
GROUP BY a.name
HAVING COUNT(*) BETWEEN 2 AND 5;
fyi, the above query would deliver a result like this if i call it directly on the database:
1, John
2, Donald
1, Ralph
...
Alternatively, you can use
SQLQuery query = session.createSQLQuery("SELECT count(*) as num, a.name as name FROM user a WHERE a.user_id IN (SELECT b.user_id FROM user b) GROUP BY a.name HAVING COUNT(*) BETWEEN 2 AND 5;";
query.addScalar("num", Hibernate.INTEGER).addScalar("name", Hibernate.STRING);
// you might need to use org.hibernate.type.StandardBasicTypes.INTEGER / STRING
// for Hibernate v3.6+,
// see https://hibernate.onjira.com/browse/HHH-5138
List<Object> result = query.list();
// result.get(2*i + 0) -> i-th row num
// result.get(2*i + 1) -> i-th row name
I'm using this in case of time-pressure, imo much faster to code then creating your own beans & transformers.
Cheers!
Jakub
cheers for the info Thomas, worked wonderful for generating objects
the problem i had with my initial query was that "count" was a reserved word :P
when i changed the name to something else it worked.
If your SQL statement looks like this SELECT count(*) as count, a.name as name... you could use setResultTransformer(new AliasToBeanResultTransformer(YourSimpleBean.class)) on your Query.
Where YourSimpleBean has the fields Integer count and String name respectively the setters setCount and setName.
On execution of the query with query.list() hibernate will return a List of YourSimpleBeans.