mysql - retrieve row based of indirect referencing -


i'm having trouble query. based on primary key, have use foreign key in same tuple/row access table foreign key primary key.

i have no idea how approach since can't save foreign key in variable example.

tldr query this;

 1. use user input search primary key  2. requested row  3. use column in row search table  4. second requested row  5. return contents 2 rows requested.  select * table1 table1.primarykey = 'userinput' union select * table2, table1 table1.foreignkey = table2.foreignkey; 

this have far, doesn't work. illustrates point.

usually 2 queries, i'd rather in one.

what using joins ?

select * table2   join table1      on table1.foreignkey = table2.foreignkey table1.primarykey = 'userinput' 

or, way be:

select * table1, table2 table1.foreignkey = table2.foreignkey       , table1.primarykey = 'userinput' 

Comments

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

java - Android – MapFragment overlay button shadow, just like MyLocation button -