How to use composite keys index in join tables

QuestionsHow to use composite keys index in join tables
Hong asked 11 years ago

select_command = select concat(p.proj_id,'-',cabs.cab_id) as 'key',
FROM projects p
LEFT JOIN cabs ON p.proj_id = cabs.proj_id_f

Above is my sql command. I want to have a composite key with two colums from different tables. Key is empty when there is no cabs.cab_id in a line
How can I fix this or how can I have a unique key?

1 Answers
Abu Ghufran answered 11 years ago

Hello,

You can use IFNULL() for blank left join table values.

select concat(p.proj_id,'-', IFNULL(cabs.cab_id,0) ) as 'key', ……

Also, You need to write custom on_update, on_insert. on_delete as based DML as only for single tables.

Your Answer

17 + 17 =

Login with your Social Id:

OR, enter

Attach code here and paste link in question.
Attach screenshot here and paste link in question.



How useful was this discussion?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate it.

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?