Sql Query

  • itHighway
  • Newbie
  • Newbie
  • itHighway
  • Posts: 7

Post 3+ Months Ago

I need help with a sql query. To make it easier to understand I

created an image. Please click on link below to see the image.


  • mrbigdog
  • Born
  • Born
  • mrbigdog
  • Posts: 4

Post 3+ Months Ago

Try this dude, should work fine...

FROM tblListings, tblListingsFloorPlan
WHERE tblListings.IngListingId = tblListingsFloorPlan.IngListingId
AND tblListingsFloorPlan.txtBath = '2'

Problem was, you were not using an INNER join correctly.

Ps. 'I used MYSQL Meistro' myself and would say I learnt more from doing it myself...

You could change the '2' to a form field selected by the user if you wish.

Let me know if you need more help...

  • righteous_trespasser
  • Scuffle
  • Genius
  • User avatar
  • Posts: 6231
  • Loc: South-Africa

Post 3+ Months Ago

Code: [ Select ]
SELECT DISTINCT tblListings.lngListingId, tblListingsFloorPlan.lngFloorPlanId FROM tblListings LEFT JOIN tblListingsFloorPlan ON tblListings.IngListingId = tblListingsFloorPlan.IngListingId WHERE tblListingsFloorPlan.txtBed='2'

if txtBed is an integer field it shouldn't be in quotation marks ... but mrbigdog's looks as if it would work aswell ... try his first seeing that it's shorter ... otherwise try mine ... I just did it straight out of my head, so there might be some spelling mistakes or something like that ... also on mine try changing the "LEFT JOIN" to a "RIGHT JOIN" or an "INNER JOIN" if it doesn't work straight off ...
  • joebert
  • Genius
  • Genius
  • User avatar
  • Posts: 13511
  • Loc: Florida

Post 3+ Months Ago

If you're not using a MySQL version prior to MySQL 5.0.12

Code: [ Select ]
SELECT DISTINCT lngListingId, txtTitle
FROM tblListings NATURAL JOIN tblListingsFloorPlan
WHERE txtBed = 2
  1. SELECT DISTINCT lngListingId, txtTitle
  2. FROM tblListings NATURAL JOIN tblListingsFloorPlan
  3. WHERE txtBed = 2

If you get an error about an txtBed being an ambiguous column, you're using a version prior to 5.0.12

Post Information

  • Total Posts in this topic: 4 posts
  • Users browsing this forum: No registered users and 36 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum

© 1998-2016. Ozzu® is a registered trademark of Unmelted, LLC.