PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, April 19, 2022

[FIXED] How to resolve ambiguous error in the query

 April 19, 2022     join, laravel, laravel-query-builder, mysql, sql     No comments   

Issue

I am using laravel framework for developing API's ,i have one query that is executed without where condition without any error i need to execute with where condition but it's throwing an error

query

select count(*) as aggregate
from `users`
  left join `books` on `books`.`book_id` = `books`.`id`
where `access_id` = 5054

SQL Error [1052] [23000]: Column 'access_id' in where clause is ambiguous

after searching google i got something we have to specify reference of a table name , i added reference name like this where users.access_id =5054 but it's throwing an error like unknown column but in my db i have that column in both users and books table


Solution

The problem is its consider as a column so that's why syntax error is coming,try following way it will resolve your problem

select count(*) as aggregate
from `users`
  left join `books` on `books`.`book_id` = `books`.`id`
where `users`.`access_id` = 5054



Answered By - Sai Tarun
Answer Checked By - Mildred Charles (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing