I am using OSTICKET 1.9.12 on Ubuntu 12.
Is there any way I can get registered user 'phone number' via mysql query?
I tried to search on there forums and internet, but didn't got any working method.
Hopefully your problem would have been solved by now, but if not, you can try this query:
SELECT T3.value FROM %table_prefix%_user T1
JOIN %table_prefix%_form_entry T2 on T1.id = T2.object_id
Join %table_prefix%_form_entry_values T3 on T2.id = T3.entry_id
where T1.id=5 and T3.field_id=3;
In order for this to work, replace %table_prefix% with the table prefix in your OSTicket database. Also replace '5' in where clause (T1.id=5) to the user's id.
Related
Does PostgreSQL have a pseudo-column like "LEVEL" in Oracle?
If not, then how can we create a column similar to "LEVEL"?
Postgres does not have hierarchical queries. No CONNECT BY, therefore also no LEVEL.
The additional module tablefunc provides the function connectby() doing almost the same. See
mthorley answer for details.
Or you can use a standard recursive CTE with a level column that's incremented with every recursion.
This query in Oracle:
SELECT employee_id, last_name, manager_id, LEVEL
FROM employees
CONNECT BY PRIOR employee_id = manager_id;
.. can be translated to this recursive CTE in Postgres:
WITH RECURSIVE cte AS (
SELECT employee_id, last_name, manager_id, 1 AS level
FROM employees
UNION ALL
SELECT e.employee_id, e.last_name, e.manager_id, c.level + 1
FROM cte c
JOIN employees e ON e.manager_id = c.employee_id
)
SELECT *
FROM cte;
Yes, Postgres has support for "LEVEL" like Oracle.
But, as the other answers point out, you must have the tablefunc extension loaded.
If you have admin access to your Postgres database you can load it with this:
CREATE EXTENSION IF NOT EXISTS tablefunc;
For additional info check the docs
https://www.postgresql.org/docs/current/static/tablefunc.html
Here's a real life example of connectby from one of our apps. We are using it to find all the people who report up to a manager through their reporting tree.
SELECT system_user.system_user_id
, system_user.first_name
, system_user.last_name
, team.mgr_id as managers_system_user_id
, team.level
, team.hierarchy
FROM connectby('system_user_manager_rltnp'
, 'system_user_id'
, 'system_users_managers_id'
, 2963049 -- the users system_user_id
, 5 -- the max levels of depth
, '~') -- the hierarchy delimiter
AS team(rpt_id numeric, mgr_id numeric, level int, hierarchy text),
system_user
WHERE team.rpt_id = system_user.system_user_id
And it returns results like this. Here you can see the level, and also the whole hierarchy as a string.
"system_user_id","first_name","last_name","managers_system_user_id","level","hierarchy"
"2963049","Debbie","Buswell","",0,"2963049"
"2963045","Linda","Simply","2963049",1,"2963049~2963045"
"2963047","Cindy","Brouillard","2963049",1,"2963049~2963047"
"2963048","Sharon","Burns","2963049",1,"2963049~2963048"
"2963050","Marie-Eve","Casper","2963049",1,"2963049~2963050"
"2963051","Tammy","Cody","2963049",1,"2963049~2963051"
The functionality using a Connect By, Starts With, and a level indicator that you are familiar with is available if you enable the tablefunc extension in postgres. The syntax is slightly different, but if you understand connect by from oracle you will pick this up in about 90 seconds. It is great and saved my bacon when I transformed an oracle system into a postgres system.
I gave all the detail to a similar question.
Stackoverflow Connect By answer
I have this sql statement setup in my old code and want to move it over to active record, the problem that I'm phased with is how do I do a
SELECT news_items.id FROM
(SELECT news_items.* FROM news_items
JOIN feeds ON feeds.id=news_items.feed
LEFT JOIN news_item_country ON news_item_country.id=news_items.country
WHERE news_items.id=30758
ORDER BY date_item DESC )
AS news_items
GROUP BY news_items.id
ORDER BY date_item DESC
Trying to do this with Active Record, first I created the select that goes inside the select at least that is what I think needs to be done.
$news_items = $this->db->select('default_news_items.*')
->from('default_news_items ')
->join('default_feeds','default_feeds.id=default_news_items.feed')
->join('default_news_item_country','default_news_item_country.id=default_news_items.country','left')
->join('default_news_item_options','default_news_item_options.id=default_news_items.options','left')
->where($where)
->order_by('date_item DESC')
->limit($limit)
->get();
Next I create the actual select and reference the other select inside the from
if ($query = $this->db->select("
news_items.id,
->from($news_items)
->group_by('news_items.id')
->get()) {
It did not work, so I'm asking if someone have experiences with this and how to do it?
You can't do a subquery directly in native active record syntax. Check out this answer for a solution:
subquery in codeigniter active record
(The author wrote a library for active record subqueries http://labs.nticompassinc.com/CodeIgniter-Subqueries/ )
Without this or similar technique you need to keep your current select code at least for the subquery ($news_items).
Take a look at this answer of mine this might help how you can achieve it.
Using Mysql WHERE IN clause in codeigniter
I have prepared few queries using startwith and connectby for fetching all items of a table with parent - childs relationship.
Till now, these queries were working perfectly fine. But now, i noticed the hierarchy returned was not the same. hierarchy is returned in totally random way, although the data is same.
Can anyone suggest why this is happening..
Below is the sample query:
SELECT id,loc.title Title FROM
(SELECT level level,id id,parent_id Parent_Id,sort_order FROM table1
START WITH parent_id=0
CONNECT BY prior id = parent_id ORDER SIBLINGS BY sort_order)
INNER JOIN table2 loc ON id = loc.id WHERE loc.locale=?
the ORDER SIBLINGS BY will do what you want if you don't wrap the query as an inline view.
once you wrap it, then the ordering is no longer specified
i would suggest doing the JOIN directly in the inner query.. then your order by should work.
I have been using SQL Server 2008 for a short time now and have never used Oracle before. I am able to access an Oracle table through SQL Server with the syntax
select * from [OracleDB1]..[OracleDB1].[Zips]
(where OracleDB1 is the oracle database and Zips is the table I require)
Is it possible to join a SQL Server table with this one in a Table-valued Function? Just using a normal join as I would with SQL Server tables gives an Invalid object name error on the Oracle table.
Can this be done directly (or at all) or is it possible to do this some other way such as table variables?
example query:
select * from dbo.Table1 t INNER JOIN [OracleDB1]..[OracleDB1].[Zips] z where t.zip = z.zip
I was performing the join wrong since I missed the ON clause. I was able to get it to work by declaring a temptable and joining on that.
declare #tempTable table{
ZIP nvarchar(5),
COUNTY nvarchar(10)
}
insert #tempTable select ZIP, COUNTY, from [OracleDB1]..[OracleDB1].[ZIPS]
select * from dbo.Table1 t INNER JOIN #tempTable z on t.ZIP = v.ZIP where t.AdmissionOn >= '08-08-2011' AND t.AdmissionOn <= ''09-08-2011'
This also worked in line as I had in the original question once I added the ON clause but the table variable suits my needs better since it only has to access the Oracle table once and not each comparison.
How can I use In clause in Hive
I want to write something like this in Hive
select x from y where y.z in (select distinct z from y) order by x;
But I am not finding any way of doing it..
I tried In clause in Hive 0.7 it was throwing error, Also I tried Find_in_Set ..
using find_in_set(y.z,subquery).. but the job is getting failed.
I want to do this on Hive. Please help me if anybody knows how to do this in Hive..
Thanks & Regards,
Atul
You can use semi join(https://cwiki.apache.org/Hive/languagemanual-joins.html):
LEFT SEMI JOIN implements the correlated IN/EXISTS subquery semantics in an efficient way. Since Hive currently does not support IN/EXISTS subqueries, you can rewrite your queries using LEFT SEMI JOIN. The restrictions of using LEFT SEMI JOIN is that the right-hand-side table should only be referenced in the join condition (ON-clause), but not in WHERE- or SELECT-clauses etc.
SELECT a.key, a.value
FROM a
WHERE a.key in
(SELECT b.key
FROM B);
can be rewritten to:
SELECT a.key, a.val
FROM a LEFT SEMI JOIN b on (a.key = b.key)
Hive 0.13 now do support IN/EXISTS in the WHERE-clause .. The issue https://issues.apache.org/jira/browse/HIVE-784 has been resolved after 4 years :)
According to https://cwiki.apache.org/confluence/display/Hive/LanguageManual+Select:
"Hive does not support IN, EXISTS or subqueries in the WHERE clause."
You might want to look at:
https://issues.apache.org/jira/browse/HIVE-801
https://issues.apache.org/jira/browse/HIVE-1799
I'm using hive version 0.7.1 and SELECT * FROM MYTABLE WHERE MYCOLUMN IN ('thisThing','thatThing');
I tested this on a column type STRING so I am not sure if this works universally on all data types since I noticed like Wawrzyniec mentioned above that the Hive Language Manual says that it is not supported and to instead use LEFT SEMI JOIN but it worked fine in my test.
Hive supports perfectly the IN ... it does not support the subquery in the WHERE clause
there is an open feature ticket from Facebook engineers since 4 years...
https://issues.apache.org/jira/browse/HIVE-784?focusedCommentId=13579059
assume table t1(id,name) and table t2(id,name)
listing only those ids from t1 that exists in t2(basically IN clause)
hive>select a.id from t1 a left semi join t2 b on (a.id=b.id);
listing only those ids from t1 that exists only in t1 but not in t2(basically NOT IN clause)
hive>select a.id from t1 a left outer join t2 b on(a.id=b.id) where b.id is null;
Hive does support IN/EXISTS statements since Hive 0.13 with few limitations. Please refer to https://cwiki.apache.org/confluence/display/Hive/LanguageManual+SubQueries for more details.