John Lenner
John Lenner

Reputation: 19

#1064 - You have an error in your SQL syntax in phpMyadmin

I built the following Query, for MySQL, on Maria Db, phpMyAdmin Ver: 4.8.3

Database server

Server: 127.0.0.1 via TCP/IP
Server type: MariaDB
Server connection: SSL is not being used Documentation
Server version: 10.1.36-MariaDB - mariadb.org binary distribution
Protocol version: 10

Web server

Apache/2.4.34 (Win32) OpenSSL/1.1.0i PHP/7.2.10
Database client version: libmysql - mysqlnd 5.0.12-dev - 20150407 - $Id: 38fea24f2847fa7519001be390c98ae0acafe387 $
PHP extension: mysqliDocumentation curlDocumentation mbstringDocumentation
PHP version: 7.2.10

SQL

SELECT tblhoadon.MaHoaDon, 
       tblkhachhang.HoVaTen, 
       tblphongtro.MaSoPhong, 
       tblphongtro.GiaThue, 
       tbldichvu.MaDichVu, 
       tblchitietdv.TenChiPhi, 
       tblchitietdv.ThanhTien, 
       tblhoadon.TongTien 
FROM tblhoadon, 
     tblphongtro,
     tbldichvu,
     tblchitietdv 
WHERE tblhoadon.MaKhachHang = tblkhachhang.MaKhachHang, 
      tblhoadon.MaSoPhong   = tblphongtro.MaSoPhong,
      tblhoadon.MaDichVu    = tbldichvu.MaDichVu,
      tbldichvu.MaDichVu    = tblchitietdv.MaDichVu LIKE 10040001

Report error

1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use

near ' tblhoadon.MaSoPhong = tblphongtro.MaSoPhong, tblhoadon.MaDichVu = tbldichvu.MaD' at line 1

Can you help me fix syntax error?

Upvotes: 1

Views: 1201

Answers (1)

Mureinik
Mureinik

Reputation: 311163

You can't just have a series of conditions. You need some logical operator between them, such as and or or. Additionally, the last condition has several issues:

  1. like` should take a string argument, not a number
  2. You can't chain equalities like that, you should create two conditions with a logical and operator between them.
  3. While it's not strictly wrong to use like without a wildcard, it's a bit pointless, and you can just use an = condition:


SELECT tblhoadon.MaHoaDon, 
       tblkhachhang.HoVaTen, 
       tblphongtro.MaSoPhong, 
       tblphongtro.GiaThue, 
       tbldichvu.MaDichVu, 
       tblchitietdv.TenChiPhi, 
       tblchitietdv.ThanhTien, 
       tblhoadon.TongTien 
FROM tblhoadon, 
     tblphongtro,
     tbldichvu,
     tblchitietdv 
WHERE tblhoadon.MaKhachHang = tblkhachhang.MaKhachHang AND 
      tblhoadon.MaSoPhong   = tblphongtro.MaSoPhong AND
      tblhoadon.MaDichVu    = tbldichvu.MaDichVu AND
      tbldichvu.MaDichVu    = tblchitietdv.MaDichVu AND
      tblchitiedv.MaDichVu = '10040001'

Upvotes: 1

Related Questions