Display the object names and types from the USER_OBJECTS data dictionary view EMPLOYEE and DEPARTMENT tables - sqlplus

I'm having trouble with the where clause...
SELECT OBJECT_NAME, OBJECT_TYPE
FROM USER_OBJECTS
WHERE TABLE_NAME IN ('EMPLOYEE', 'DEPARTMENT');

Figured it out -
SELECT constraint_name, constraint_type
FROM user_constraints
WHERE table_name IN ('EMPLOYEE', 'DEPARTMENT');

Related

alias column names without mentioning column name

I'm trying to get all columns from each table with a prefix in the output, without mentioning all column names specifically in the select statement. Like:
SELECT *
FROM TABLE1 as T1
FULL JOIN TABLE2 as T2
ON T1.number=T2.number
Where I would want to get all column names from table1 and table2 prefixed with "T1" and "T2".
Many thanks in advance!
SELECT
CONCAT('T1', COLUMN_NAME), ORDINAL_POSITION
FROM
INFORMATION_SCHEMA.COLUMNS
WHERE
TABLE_NAME = 'TABLE1'
ORDER BY 2
UNION
SELECT CONCAT('T2', COLUMN_NAME), ORDINAL_POSITION
FROM
INFORMATION_SCHEMA.COLUMNS
WHERE
TABLE_NAME = 'TABLE2'
ORDER BY 2

Join tables in Hive using LIKE

I am joining tbl_A to tbl_B, on column CustomerID in tbl_A to column Output in tbl_B which contains customer ID. However, tbl_B has all other information in related rows that I do not want to lose when joining. I tried to join using like, but I lost rows that did not contain customer ID in the output column.
Here is my join query in Hive:
select a.*, b.Output from tbl_A a
left join tbl_B b
On b.Output like concat('%', a.CustomerID, '%')
However, I lose other rows from output.
You could also achieve the objective by a simple hive query like this :)
select a.*, b.Output
from tbl_A a, tbl_B b
where b.Output like concat('%', a.CustomerID, '%')
I would suggest first extract all ID's from free floating field which in your case is 'Output' column in table B into a separate table. Then join this table with ID's to Table B again to populate in each row the ID and then this second joined table which is table B with ID's to table A.
Hope this helps.

Update statement with Join in Informix

I need to select an employee_id from a table
select emp_id
from employee emp, temp_data td where lower(td.supervisor_name) like lower(emp.last_name||emp.firstname)
and insert it into a field in the same table
update emp set emp.supervisor_id = **The value returned from the previous query**
from employee as emp
Inner join temp_table as td
on td.emp_id = emp.emp_id
Is there any way that I can achieve it? The problem is that I am referring to another field of the same table while setting it in the update statement.. Please let me know if there is any other route I could go... I am doing it in Informix.
I think you need to check your data
done following check
table : temp_data table has following data
supervisor_name
------------------------------
kaushal
abc
solanki
def
table : employee table has following values
firstname last_name
------------------------------
ajay jadeja
sachin solanki
kaushal kumar
manish galav
1.
select supervisor_name from temp_data
select firstname from employee
Note the result
1 record named kaushal which is match . So you need to update the the ID of kaushal
2.
select supervisor_name from temp_data
select last_name from employee
1 record named solanki matches. So you need to update the the ID of solanki
see the result
Note how many rows you need to update (here 2)
First try your select query put into update query
then you said it gaves error ..
then Try this :
Modified your select query as below and put it into your update query.
select emp_id
from employee emp, temp_data td
where
( lower(td.supervisor_name) like lower(emp.last_name )
or
lower(td.supervisor_name) like (emp.firstname) )
)
see the result 2 rows update or not ...????????
Try this also it successfully update your data.
MERGE INTO employee as emp
USING temp_data as td
ON emp.emp_id = td.emp_id
and ( lower(td.supervisor_name) like lower(emp.last_name)
or
lower(td.supervisor_name) like lower(emp.firstname) )
WHEN MATCHED THEN UPDATE set emp.supervisor_id = emp.emp_id

Searching a column name across a database in oracle9i?

Is there a way to search to which table or tables a column(say Cycle_name) belongs to in oracle?
Select *
from all_tab_cols
where column_name like '%%'
If you want also to spiecified a table add the following to WHERE clause
table_name like '%%'

After joining tables with zend framework , it just show me one tables field

I have 2 tables product_category and product_sub_category
The names of the fields are identical (id,name,explain,priority)
product_sub_category has an foreign key to the product_category table with as product_category_id.
With the code below all I see is product_category fields
$select = $this->select("t1.* , t2.*")
->setIntegrityCheck(false)
->from(array("t1"=>$this->_name))
->joinInner(array("t2"=>'product_category'), 't2.id = t1.product_category_id')
->order(array('t1.priority'));
$res = $this->fetchAll($select);
return $res;
In $this->_name variable should be a string product_sub_category.
Why can I not see all fields from both tables?
MySQL will return the fields with the same name, so when ZF converts them to an array using the name as the index, the latter will overwrite the first. You'll need to give them aliases instead:
$this->select("t1.name AS category_name, t1.explain AS category_explain, t2.name AS subcategory_name")
and so on.

Resources