join = db.ntw_edge.with_alias('alias_edge').on(db.ntw_edge.inID == db.alias_edge.outID)
db((db.ntw_edge.outID == 1622) & (db.ntw_edge.labelID == db.alias_edge.labelID)).select(join=join)
SELECT "ntw_edge"."id", "ntw_edge"."outID", "ntw_edge"."inID", "ntw_edge"."labelID", "ntw_edge"."networkkey"
FROM "ntw_edge"
JOIN "ntw_edge" AS "alias_edge" ON ntw_edge.inID = alias_edge.outID
WHERE (("ntw_edge"."outID" = 1622) AND ("ntw_edge"."labelID" = "alias_edge"."labelID"))
This:
join = db.ntw_edge.with_alias('alias_edge').on('ntw_edge.inID = alias_edge.outID')
db((db.ntw_edge.outID == 1622) & 'ntw_edge.labelID = alias_edge.labelID').select(join=join)will produce this:
SELECT "ntw_edge"."id", "ntw_edge"."outID", "ntw_edge"."inID", "ntw_edge"."labelID", "ntw_edge"."networkkey"
FROM "ntw_edge"
JOIN "ntw_edge" AS "alias_edge" ON ntw_edge.inID = alias_edge.
outID
WHERE (("ntw_edge"."outID" = 1622) AND ntw_edge.labelID = alias_edge.labelID)
Hi Anthony,
Thanks for your reply.
I get the results I want. Two more questions, using this syntax, how would I join
ntw_edge_inID on vtx_vertex.id
and
ntw_edge_labelID on ntw_edge_label_set.id
without ending up with more records than I have now.
Second, up to now I have been writing joins using this syntax:
rows = ((db.ntw_edge.outID==vertexID) & (db.ntw_edge.inID==alias_edge.outID) &
(db.ntw_edge.labelID==alias_edge.labelID) .select()
However, this does not always give me the results I want for it mixes the join with the
where clause. Am I right to conclude that the way you coded the join is the best way
to do it?
When I want to add a LEFT JOIN, do I add it to the select() part as I did before:
left=[db.lct_address.on((db.ntw_edge.inID==db.lct_address.vertexID) &
(db.lct_address.label==PHYSICALADDRESSID)),
db.app_settings.on((.ntw_edge.inID==db.app_settings.vertexID) & (db.app_settings.openID==PUBLIC))],
What is the SQL you are trying to produce?
db((db.ntw_edge.outID == 1622) & (db.ntw_edge.labelID == db.ntw_edge.with_alias('alias_edge').labelID)).select(
join=[db.alias_edge.on(db.ntw_edge.inID == alias_edge.outID),
db.vtx_vertex.on(db.ntw_edge.inID == db.vtx_vertex.id),
db.ntw_edge_label_set.on(db.ntw_edge.labelID == db.ntw_edge_label_set.id)])