mahmoudghalayini's avatar

Remove duplicate values

How to remove duplicate values while selecting from table in database.

[ { A: "test", B: "test1" }, { A: "test1", B: "test" }, { A: "test2", B: "test1" }, { A: "test2", B: "test" } ]

0 likes
6 replies
MichalOravec's avatar

Yeah, because it was just an example, I don't know what should be your output. Just change logic inside of that unique funtion.

Tray2's avatar

You can use distinct in your query.

SELECT DISTINCT name FROM books;
$users = DB::table('users')select('name')->distinct()->get();

Not able to test the eloquent version at the moment but I think it should work.

tykus's avatar

What are the duplicates here? Duplicates of A, or duplicates of B, or duplicates of AB?

Please or to participate in this conversation.