what is the meaning of (+) operator in pl/sql eg:- rec.ptp_id= PTP.ptp_id(+)
Is it left outer join when we specify (+) in right?
Its outer join ,left outer join
Related
I want to know, what constitutes as the left table and the right table after the first join.
For example:
From final_productions fp
left join things.pc p on fp.production_id = p.id
left join events.time t on fp.tx_id = t.id
left join things.car c on c.id = fp.channel_id
right join events.form f on f.production_id = p.id
left join events.trigger_alert ta on mc.cue_sheet_id = ta.id
I know for the first left join inner join things.pc p on fp.production_id = p.id the left table would be the table in the from statement which is final_productions. But what about the other joins(i.e the joins after the first join statement)? Could someone explain this, please? Thanks
The documentation says:
Parentheses can be used around JOIN clauses to control the join order. In the absence of parentheses, JOIN clauses nest left-to-right.
So
a LEFT JOIN b RIGHT JOIN c
is the same as
(a LEFT JOIN b) RIGHT JOIN c
I have a query I am trying to save as a view but SSMS returns an error stating there are multiple columns with the same name.
I have tried to rename the affected columns as an alias but without success.
Column names in each view or function must be unique. Column name 'codemanQuestionID' in view or function 'vwBlocks' is specified more than once.
create view vwBlocks as
SELECT
LUConstructionType.codemanOptionID AS LUConstruction_codemanOptionID
, LUFascias.codemanOptionID AS LUFascias_codemanOptionID
, Block.windowsID
, LUWindows.windows
, LUWindows.codemanQuestionID AS codemanQuestion_ID
, Block.externalDoorID
, LUExternalDoor.externalDoor
, LUExternalDoor.codemanOptionID as LUExternal_codemanOptionID
FROM Block LEFT OUTER JOIN
LUOwnership ON Block.ownershipID = LUOwnership.ownershipID LEFT OUTER JOIN
LULocalAuthority ON Block.localAuthorityID = LULocalAuthority.authorityTypeID LEFT OUTER JOIN
LUConstructionType ON Block.constructionTypeID = LUConstructionType.constructionTypeID LEFT OUTER JOIN
LUTV ON Block.TVID = LUTV.TVID LEFT OUTER JOIN
LUSatellite ON Block.satelliteID = LUSatellite.satelliteID LEFT OUTER JOIN
LUPlayArea ON Block.playArea = LUPlayArea.playAreaID LEFT OUTER JOIN
LURoofCovering ON Block.roofCoveringID = LURoofCovering.roofCoveringID LEFT OUTER JOIN
LUFascias ON Block.fasciasID = LUFascias.fasciasID LEFT OUTER JOIN
LUWindows ON Block.windowsID = LUWindows.windowsID LEFT OUTER JOIN
LUExternalDoor ON Block.externalDoorID = LUExternalDoor.externalDoorID LEFT OUTER JOIN
LUcontractorInfo ON Block.contractorInfoID = LUcontractorInfo.contractorID LEFT OUTER JOIN
LUagentInfo ON Block.agentInfoID = LUagentInfo.agentID LEFT OUTER JOIN
LULandlord ON Block.LandlordID = LULandlord.landlordID LEFT OUTER JOIN
LUblockStatus ON Block.blockStatusID = LUblockStatus.blockStatusID LEFT OUTER JOIN
LUPropertyGroup ON Block.propertyGroup = LUPropertyGroup.propertyGroupID LEFT OUTER JOIN
LUCommunalBoilerType ON Block.communalBoilerType = LUCommunalBoilerType.communalBoilerID LEFT OUTER JOIN
LUExternalAreaManagedBy ON Block.externalAreaManagedBy = LUExternalAreaManagedBy.managedByID LEFT OUTER JOIN
LUgasBoilerMakeModel ON Block.CommBoilerMakeModelID = LUgasBoilerMakeModel.makeModelId LEFT OUTER JOIN
LUMaintenanceResp ON Block.maintenanceRepID = LUMaintenanceResp.maintenanceRepID
Can anybody recommend a solution please?
Thanks for any help in advance.
I'm not seeing codemanQuestionID twice. Here's some advice that has helped me a ton avoid and/or troubleshoot issues like this.
There are at least four ways to alias a column:
(expression) AS ((alias))
((alias)) = (expression)
WITH ((cte name)) ((alias1), (alias2),...
FROM ((subquery)) AS ((alias1>),(alias2,...
AS is the worst IMO. Its sloppy and confusing, especially when you don't include AS. The aliasing style I usually go with is:
SELECT
col1 = <expression>,
col2 = <expression>,
colABC = <expression>
FROM schema.table1 AS t1
JOIN schema.table2 AS t2;
This has made debugging waaay easier.
In MySQL I can do a nested join. With Eloquent is it possible?
LEFT JOIN users_permissions (
INNER JOIN permissions
ON permissions.id = user_permissions.id_permission
LEFT JOIN permissions_feature
ON permissions_feature.id = user_permissions.id_permission_feature
) ON users_permissions.user_id = users.id
Basically, the first LEFT JOIN will works if ON matches, but it requires that INNER JOIN match too. Additionally, another LEFT JOIN is done if all works.
With Eloquent it seems not be possible, because JoinClause don't have a join() method.
I am newbie in postgres. I have a query
SELECT * FROM orders
LEFT OUTER JOIN order_details ON order_details.orderid= orders.orderid
an it get error
SQL error:
ERROR: column order_details.orderid doesn't exist
LINE 2: LEFT OUTER JOIN order_details ON order_details.orderid...
^
In statement:
SELECT COUNT(*) AS total FROM (SELECT * FROM orders
LEFT OUTER JOIN order_details ON order_details.orderid= orders.orderid) AS sub
What am i missing in my query?
Thanks before
Postgres is case sensitive. Your SQL statement must be in the correct case, and if the table name or column name is not lower case then you must enclose it in double quotation marks. (as shown below)
SELECT * FROM orders
LEFT OUTER JOIN order_details ON order_details."OrderID"= orders.orderid
My query is as below:
Select
array_to_string(r.media,',') AS service_type,
array_to_string(array_agg(distinct s.state_name), ',') as primary_location
FROM contract.contract c
LEFT JOIN customer.customer_state s , contract.rights r ON s.id = ANY (r.state)
WHERE c.customer_code::text = 'YYYY'::text
group by r.state
order by c.contract_name asc;
and I'm getting:
ERROR: syntax error at or near "," LINE 44: LEFT JOIN
customer.customer_state s , contract.rights r O...
Please suggest
You can't mix explicit and implicit joins like that.
FROM contract.contract c
LEFT JOIN customer.customer_state s , contract.rights r ON
^^^
You should use explicit INNER JOIN or CROSS JOIN terms if you're going to be including LEFT JOIN terms.
The predicate for a join must always immediately follow the join, without other extras.
If you want to do a left join on multiple tables, you must chain the left joins.
FROM contract.contract c
LEFT JOIN customer.customer_state s ON (...)
LEFT JOIN contract.rights r ON (...)
Guesswork from here on in, as the original query's intent is unclear.
Perhaps you mean
FROM contract.contract c
INNER JOIN customer.customer_state s ON (...??...)
LEFT JOIN contract.rights r ON (s.id = ANY (r.state))
though I don't see any predicate that connects contract to either rights or customer_state in the original, so it's hard to guess your intent. If you actually intended a cartesian product (cross join) you'd write:
FROM contract.contract c
CROSS JOIN customer.customer_state s
LEFT JOIN contract.rights r ON (s.id = ANY (r.state))