Sql Query

  • itHighway
  • Newbie
  • Newbie
  • No Avatar
  • Joined: Jan 27, 2008
  • Posts: 7
  • Status: Offline

Post March 15th, 2008, 12:34 pm

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.

http://realestate.ithighway.co.uk/upload/sqlQuery.gif


Thanks!
  • Anonymous
  • Bot
  • No Avatar
  • Joined: 25 Feb 2008
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post March 15th, 2008, 12:34 pm

  • mrbigdog
  • Born
  • Born
  • No Avatar
  • Joined: Mar 15, 2008
  • Posts: 4
  • Status: Offline

Post March 15th, 2008, 4:13 pm

Try this dude, should work fine...

SELECT *
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...

Paul
  • righteous_trespasser
  • Scuffle
  • Genius
  • User avatar
  • Joined: Mar 12, 2007
  • Posts: 6228
  • Loc: South-Africa
  • Status: Offline

Post March 17th, 2008, 1:24 am

or
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 ...
Let's leave all our *plum* where it is and go live in the jungle ...
  • joebert
  • Sledgehammer
  • Genius
  • No Avatar
  • Joined: Feb 10, 2004
  • Posts: 13455
  • Loc: Florida
  • Status: Offline

Post March 17th, 2008, 3:08 am

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
Strong with this one, the sudo is.

Post Information

  • Total Posts in this topic: 4 posts
  • Users browsing this forum: No registered users and 228 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
 
cron
 

© 2011 Unmelted, LLC. Ozzu® is a registered trademark of Unmelted, LLC.