How would I write a select all query in GraphSQ. Is Select * possible with introspection on?
Also did the syntax change as I see T. required in some versions?
query: """select * from "categories" where label = $1"""
or
query: """select T.* from "categories" T where T."label" = $1"""
Related
Would love to get some help here understanding an unexpected behavior with an Oracle SELECT query. And maybe there is a nicer way to construct my query.
Basically, this is the query that gets me the distinct set of IDs that I'm after:
select distinct(c.LOCATIONID) from COURSESESSION c where c.MARKETID=280 and c.STATUSID in(1, 2)
and c.COURSESESSIONID not in (SELECT distinct(REGISTRATION.COURSESESSIONID) FROM REGISTRATION)
But I also want all the data for these distinct IDs form COURSESESSION table, so I'm wrapping the above query in yet another select statement, so it looks like this:
select * from COURSESESSION cs where cs.COURSESESSIONID in
(select distinct(c.LOCATIONID) from COURSESESSION c where c.MARKETID=280 and c.STATUSID in(1, 2)
and c.COURSESESSIONID not in (SELECT distinct(REGISTRATION.COURSESESSIONID) FROM REGISTRATION));
The first query returns a set of 21 records, but the second set returns 19, so I'm pretty sure I'm not doing this right. The triple-select query is basically for these 2 steps:
Set idsSet = select distinct(c.LOCATIONID) from COURSESESSION c where c.MARKETID=280 and c.STATUSID in(1, 2)
and c.COURSESESSIONID not in (SELECT distinct(REGISTRATION.COURSESESSIONID) FROM REGISTRATION)
select * from COURSESESSION cs where cs.COURSESESSIONID in(idsSet);
Anyone knows how to fix my triple-select query?
Why can't I use a subquery factoring clause result in the where clause of as depicted in the following sql:
with rpt as(
select * from reports where caseid =
:case_id and rownum=1 order by created desc
)
select
distinct rt.trialid
from
report_trials rt
join
trial_genes tg on rt.id=tg.trialid
where
rt.reportid = rpt.id
and
tg.gene not in('TMB','MS')
The subquery is named rptand used in the select statement's where clause. When executed encountering the following error: ORA-00904: "RPT"."ID": invalid identifier
UPDATE:
In fact nested query for the same thing is also giving me the same issue. The nested subquery is only returning a single column value from a single row:
select
distinct rt.trialid
from
report_trials rt
join
trial_genes tg on rt.id=tg.trialid
where
rt.reportid = (select id from reports where caseid = :case_id and
rownum=1 order by created desc)
and
tg.gene not in('TMB','MS')
You missed to add the table rpt in your query, thus that error.
with rpt as(
select * from reports where caseid =
:case_id and rownum=1 order by created desc
)
select
distinct rt.trialid
from
report_trials rt
join
trial_genes tg on rt.id=tg.trialid
join
rpt on rt.reportid = rpt.id
where
tg.gene not in('TMB','MS')
I need to make this SQL query with Ecto:
SELECT users.*, (select count(0) from money_transactions where from_id = users.id AND created_at > '2016-1-25 0:00:00.000000') as money_transactions_today_db FROM "users" WHERE "users"."client_token" = '123'
I try to do something like this but it doesn't work:
query = from users in Like4uElixir.User,
where: users.client_token in ^tokens,
select: {users, (from money_transactions in Like4uElixir.MoneyTransaction,
where: money_transactions.from_id == users.id,
select: count(0))}
Does Ecto support subqueries? If not, how can I execute the query?
You can use query fragments:
query = from users in Like4uElixir.User,
where: users.client_token in ^tokens,
select: {users, (fragment("(SELECT COUNT(0) FROM money_transactions
WHERE money_transactions.from_id == ?)", users.id))}
Although in this case the query can also be written using regular joins and group_by. Current support for subqueries in Ecto is limited.
I want identical XPATH query to trhis SQL2 Query.
SELECT * FROM [nt:base] AS s WHERE ISDESCENDANTNODE([/content/abc/def]) and ([sling:resourceType] = 'geomatrixx/components/list' )
Is there any tool or link available through which i can convert sql2 query into xpath. or any tutorial if yes then please share the link
Below is the equilvalent XPath query.
/jcr:root/content/abc/def//element(*, cq:Page)[jcr:contains(jcr:content/#sling:resourceType, 'geometrixx/components/list')].
Below are some of the mappings between xpath and sql2 queries respectively.Taken from http://docs.jboss.org/jbossdna/0.7/manuals/reference/html/jcr-query-and-search.html.
//* SELECT * FROM [nt:base]
//element(*,my:type) SELECT * FROM [my:type]
//element(*,my:type)/#my:title SELECT [my:title] FROM [my:type]
//element(*,my:type)/(#my:title | #my:text) SELECT [my:title],[my:text] FROM [my:type]
//element(*,my:type)/(#my:title union #my:text) SELECT [my:title],[my:text] FROM [my:type]
Thanks,
Balaji
How to do this query: SELECT * FROM (SELECT * FROM some_table ORDER BY id DESC LIMIT 3) a ORDER BY id with Eloquent in Laravel4?
Thanks in advance.
I just looked it up but couldn't find a way to do it.
What you can is to just create a normal Eloquent query and then sort it by PHP.
$query = MyModel::orderBy('id', 'desc')->limit(3)->get();
$query->sortBy(function($object) {
return $object->id;
});
dd($query->toArray());
Raw: DB::select('SELECT * FROM (SELECT * FROM some_table ORDER BY id DESC LIMIT 3) a ORDER BY id');
Why using Eloquent all the time? It has so many limitations. You have 3 options when querying a database. Eloquent, Query Builder and Raw.