Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Column 'field' in where clause is ambiguous #36

Open
faustfizz opened this issue Feb 16, 2023 · 2 comments
Open

Column 'field' in where clause is ambiguous #36

faustfizz opened this issue Feb 16, 2023 · 2 comments

Comments

@faustfizz
Copy link

faustfizz commented Feb 16, 2023

 DataTables::create(db_connect()->table('user u'))
			->join("prestataire p", "p.id_prestataire = u.prestataire_id")
			->select("u.*, p.nom as name")
			->where('prestataire_id IS NOT NULL')
			.....................

I think the select function is ignored, i cann't do a custom select when fields are conflicting.

i have table user{ID, nom, prenom, prestataire_id} and prestataire{ID, nom}. I want to select with join but with no chance.

I need help !

@cikaldev
Copy link

Your code is almost correct, just another mistake to put a line of code, and get lost with your own Aliases of table.

Here i make the correct one, with inline comment and more verboses for readability.

DataTables::create(db_connect()
    // call table "users" with alias "u"
    ->table('user AS u'))
    // select whatever you want, and call another field as join
    // for better performance, better to call each collumn you want to fetch instead using wildcard
    ->select('u.*, p.nom AS name')
    // join another table "prestataire" alias "p", with condition "p.id_prestataire = u.prestataire_id"
    ->join('prestataire AS p', 'p.id_prestataire = u.prestataire_id')
    // put the where clause (don't forget to call it with prefix alias previously define)
    ->where('u.prestataire_id IS NOT NULL')
    // rest of your code here ...
    ->make()

Let us know if it's working or not,

@irsyadulibad (nimbrung ngab)

@faustfizz
Copy link
Author

Hi, thank you for replying, unfortunately it didn't work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants