1
content1{id, var1, var2, var3, created_at}
content2{id, var1, created_at}
content3{id, var1, var2, var3, va4, created_at}

I have joined 3 tables but I would like to sort and display by created_at. By joining tables, I get values from all 3 content, how do I churn data from only the content table that I need. What is the best suggestion to do this?

Many thanks.

2
  • Are you using Eloquent to fetch your data? What database software are you using? Commented May 1, 2015 at 5:13
  • Yes I am. Running off Sequel Pro in Mac @Scopey Commented May 1, 2015 at 5:21

2 Answers 2

1

Custom declaration of fields in the join. And using inner join. So

Select a.a, a.b ... etc ... innerjoin  b.a as a1, b.b as a2 ... etc ... on a.a = b.a 

Then you get the possibility of sort by a1. For instance.

Sign up to request clarification or add additional context in comments.

Comments

0

you can do multiple join with on table.

where if required and than group by method as mention below

 $records = ModelName::select('table1.id','table1.var1')
                            ->join('table2', 'table2.id', '=', 'table1.id')
                            ->join('table3', 'table3.id', '=', 'table1.id')
                            ->where('table1.var2', '=', 1)
                            ->orderBy('table3.created_at', 'ASC')
                            ->get();

1 Comment

well it's not just created_at of table3. i have to take in account of table1 and table2 as well.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.