I keep getting duplicate results - oracle-apex

I'm new to SQL and I'm using Oracle Apex. I am trying to run the following query:
Select COMPANIES.COMP_NO as "Company Id", COMP_NAME as Company",
OPEN_START_DATE as "Start Date", OPEN_TITLE as "Opening Title",
QF_CODE as "Required Qualification"
From OPENINGS, COMPANIES
Where COMP_ADDRESS='Auckland'
AND OPEN_START_DATE Between '12/01/2016' AND '12/31/2016';
I know there should only be four returned results but I keep getting duplicates of the same entry. What am I doing wrong?? I believe it must be something to do with my table connections... Thanks

select
c.comp_no,
c.comp_name,
o.start_date,
o.open_title
from
companies c
join openings o on o.comp_no=c.comp_no
where
start_date between '2016-10-01' and '2016-10-07';
use join instead of selecting it in the from clause.

Related

Netsuite suiteql how to get all available tables to query?

I am using Postman and Netsuite's SuiteQL to query some tables. I would like to write two queries. One is to return all items (fulfillment items) for a given sales order. Two is to return all sales orders that contain a given item. I am not sure what tables to use.
The sales order I can return from something like this.
"q": "SELECT * FROM transaction WHERE Type = 'SalesOrd' and id = '12345'"
The item I can get from this.
"q": "SELECT * FROM item WHERE id = 1122"
I can join transactions and transactionline for the sale order, but no items.
"q": "SELECT * from transactionline tl join transaction t on tl.transaction = t.id where t.id in ('12345')"
The best reference I have found is the Analytics Browser, https://system.netsuite.com/help/helpcenter/en_US/srbrowser/Browser2021_1/analytics/record/transaction.html, but it does not show relationships like an ERD diagram.
What tables do I need to join to say, given this item id 1122, return me all sales orders (transactions) that have this item?
You are looking for TransactionLine.item. That will allow you to query transaction lines whose item is whatever internal id you specify.
{
"q": "SELECT Transaction.ID FROM Transaction INNER JOIN TransactionLine ON TransactionLine.Transaction = Transaction.ID WHERE type = 'SalesOrd' AND TransactionLine.item = 1122"
}
If you are serious about getting all available tables to query take a look at the metadata catalog. It's not technically meant to be used for learning SuiteQL (supposed to make the normal API Calls easier to navigate), but I've found the catalog endpoints are the same as the SuiteQL tables for the most part.
https://{{YOUR_ACCOUNT_ID}}.suitetalk.api.netsuite.com/services/rest/record/v1/metadata-catalog/
Headers:
Accept application/schema+json
You can review all the available records, fields and joins in the Record Catalog page (Customization > Record Catalog).

Is there any way to get the displayed text in the "Select List" without using SQL? (Oracle APEX 21.1)

Anyone help me?
"Select List" (name: P2_SHOPS_LIST) that is created with the following SQL
SQL Statement: SELECT SHOP_NAME, GROUP_ID FROM T_ENTRY_SHOPS WHERE ID=:P2_LOV_ID;
It is necessary "GROUP_ID" because it is PK . But I need edit "SHOP_NAME" value and display to Text Field.
I think I can get the currently displayed SHOP_NAME by combining the above SQL with the selection row number, but is there any way to access this value with No SQL? Like
:P2_SHOPS_LIST.SHOP_NAME
(This gave me an error XD).
In the context of JavaScript, you can use the following
$('#P2_SHOPS_LIST option:selected').text()
This can be passed through to PL/SQL via a dynamic action, such as on change of your select list.
Or you could set your text item on change via a JS based action, using 'Set Value' and that code as the expression.

Power BI Dax Create New Table From Existing Columns

Newbie with DAX, trying to do something which I thought would be very simple but already hitting a bit of a wall and would appreciate any assistance.
I have table 'General' with columns:
'name', 'age', 'dob', 'address', 'home number', 'state'.
I have table 'Work' with columns:
'name','work address', 'company', 'mobile', 'email'.
I want to create a new (virtual?) table made of the following columns:
'General'[name], 'General'[age], 'General'[state], 'Work'[company], 'Work'[email]
Googling around, some of the solutions for creating a new table look really messy.. isn't there a super simple way to construct this? Thanks!
There are two option, first your can use "Merge Queries" option in the "Power Query Editor". You can merge two or more table this way based on Key column available in both tables. You can also use more than one Key columns for joining purpose. You can add new columns to your left table Or, you can create a new table from those two tables which is my preference. For more details, you can check this below link-
https://radacad.com/how-to-change-joining-types-in-power-bi-and-power-query#:~:text=In%20Power%20BI%20Desktop%20you,Right%20part%20of%20the%20join).
Option 2 is to create two custom columns 'Work'[company] & 'Work'[email] in the table "General". To generate value in those columns, you can use LOOKUPVALUE. Here is a sample code for that -
company =
LOOKUPVALUE(
'Work'[company]
'Work'[id], 'General'[id]
-- Guess you have common ID column in both table for joining
)

how to get an item "Database column" name

Oracle Apex 19.1.0.00.15.
how to get an item "Database column" name for IG or Form region like that exists in Oracle Forms
get_item_property('block.item',COLUMN_NAME);
I don't know of an existing function to do this, but you can obtain it like this for a form item:
select item_source
into v_column_name
from apex_application_page_items
where application_id = :APP_ID
and item_name = v_item_name;
You could wrap that in a function of your own.
There is another APEX view APEX_APPL_PAGE_IG_COLUMNS for IG columns, but I can't see how you would need that as to look up the column name you are going to need to know the column name, right?!

Oracle Apex referencing User Groups

I am trying to build an application that will be used across 6 work sites. I would like to have all staff details lodged in the same application and each staff member will have a 'Site' assigned to them (the city in which they work). When a manager from that site uses the application I would like them to only see staff in the site that they have access to.
I have been struggling with this for a while.
I have set up all the tables and pages so that all staff can be seen.
I have created user groups and assigned different users to different groups (sites). I dont know how to limit the access or even reference the group that a user is assigned to.
Any help on this topic would be greatly appreciated.
Thank you in advance
I have found a suitable solution myself. I have created a Table called 'Tbl_000_UserAccess'
In this table there are 3 columns (ID, USER ID, Site ID).
I add the user and the site ID that they can view into this table.
Then I create a view on the staff table the restricts the records to the UserID of current User. Here is my view coding for anybody that is interested:
CREATE OR REPLACE FORCE VIEW "Vw_010_Staff" ("ID", "Emp No.", "First Name", "Last Name", "Team Leader", "Coach", "JE", "CD", "IRE", "FAM", "GB", "GST", "Emp", "SLS", "Bus RADC", "KS Ind", "KS N Ind", "Anon", "OB", "Resigned", "Reason", "Site") AS
select "Tbl_010_Staff"."ID" as "ID",
"Tbl_010_Staff"."Employee Number" as "Emp No.",
"Tbl_010_Staff"."First Name" as "First Name",
"Tbl_010_Staff"."Last Name" as "Last Name",
"Tbl_011_TeamLeaders"."First Name" || ' ' || "Tbl_011_TeamLeaders"."Last Name" as "Team Leader",
"Tbl_012_Coaches"."First Name" || ' ' || "Tbl_012_Coaches"."Last Name" as "Coach",
"Tbl_014_JE"."JE" as "JE",
"Tbl_010_Staff"."Customer Details" as "CDstuff",
"Tbl_010_Staff"."IR Essentials" as "IRE",
"Tbl_010_Staff"."Family Tax Credits" as "FAM",
"Tbl_010_Staff"."General Business" as "GB",
"Tbl_010_Staff"."GST" as "GST",
"Tbl_010_Staff"."Employers" as "Emp",
"Tbl_010_Staff"."Student Loans" as "SLS",
"Tbl_010_Staff"."Business Receivables" as "Bus RADC",
"Tbl_010_Staff"."Kiwi Saver Ind" as "KS Ind",
"Tbl_010_Staff"."Kiwi Saver NonInd" as "KS N Ind",
"Tbl_010_Staff"."Anonymous" as "Anon",
"Tbl_010_Staff"."Outbound" as "OB",
"Tbl_010_Staff"."Inactive" as "Resigned",
"Tbl_010_Staff"."Inactive Reason" as "Reason",
"Tbl_010_Staff"."Site" as "Site"
from (((("Tbl_010_Staff" left outer join "Tbl_011_TeamLeaders" on "Tbl_010_Staff"."Team Leader" = "Tbl_011_TeamLeaders"."ID")
left outer join "Tbl_012_Coaches" on "Tbl_010_Staff"."Coach" = "Tbl_012_Coaches"."ID")
left outer join "Tbl_014_JE" on "Tbl_010_Staff"."JE" = "Tbl_014_JE"."ID")
left outer join "Tbl_000_UserAccess" on "Tbl_010_Staff"."Site" = "Tbl_000_UserAccess"."SiteID")
**where "Tbl_000_UserAccess"."SiteID" =
(Select "Tbl_000_UserAccess"."SiteID"
from "Tbl_000_UserAccess"
where "Tbl_000_UserAccess"."UserID" = NVL(v('APP_USER'),USER))**
This has worked perfectly. the only annoyance is that when a user is added to the schema, I will also need to add a record to the useraccess table.
Please be aware that the UserID is case sensative
Hope this helps