F
F
Fissium2018-08-17 11:32:12
MySQL
Fissium, 2018-08-17 11:32:12

How to get one of two identical records in a table?

Hello.
I join two tables in Laravel like this:

->leftJoin('articles_categories','articles.id','articles_categories.id_article')

However, the 'articles_categories' table has two 'articles_categories.id_article' entries for each 'articles.id'.
How to get only one of them?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
ixon, 2018-08-17
@ixon

Add Limit = 1. I'm not very familiar with the syntax of this DBMS, but I think it will be something like this:

->leftJoin('articles_categories','articles.id','articles_categories.id_article')->limit(1)->get();

A
Antonio Solo, 2018-08-21
@solotony

the data structure is not clear, it is not clear what you want to get. and there can be many
distinct()
first()
limit(1)
groupby()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question