473,480 Members | 5,031 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Joining to queries into one

eWish
971 Recognized Expert Contributor
I am not sure that I am taking the proper approach or even have the best design for what I am doing.

I have a table that I am storing attributes the for a real estate property listing. Each property could have one or several (many to many) attributes. Then I am storing the non-redundant data in the listing table. Instead of using two queries to get the listing and attribute data I would like to be able to do it in one without having duplicate data. I have tried a UNION but the SELECT statements have a different number of columns.
Expand|Select|Wrap|Line Numbers
  1. SELECT  listing.mlsID AS 'MLS Number',
  2.         listing.propertyAddress AS 'Property Address',
  3.         listing.description AS 'Property Description',
  4.         listing.city AS 'City',
  5.         listing.county AS 'County',
  6.         listing.state AS 'State',
  7.         listing.zipcode AS 'Zipcode',
  8.         listing.listPrice AS 'List Price',
  9.         IFNULL(listing.heatedFT, 'N/A') AS 'Heated SqFt.',
  10.         IFNULL(listing.totalFT, 'N/A') AS 'Total SqFt.',
  11.         IFNULL(listing.acres, 'N/A') AS 'Acres',
  12.         IFNULL(listing.lotSize, 'N/A') AS 'Lot Size',
  13.         IFNULL(listing.lotDescription, 'N/A') AS 'Lot Description',
  14.         IFNULL(listing.lotDimensions, 'N/A') AS 'Lot Dimensions',
  15.         IFNULL(listing.yearBuilt, 'N/A') AS 'Year Built',
  16.         listing.imageDIR AS 'Image Directory',
  17.         IFNULL(listing.directions, 'N/A') AS 'Directions',
  18.         IFNULL(listing.virtualTourUrl, 'N/A') AS 'Virtual Tour URL'
  19. FROM re_listings AS listing
  20. WHERE listing.mlsID = 555
  21. ORDER BY listing.mlsID, listing.city ASC
Expand|Select|Wrap|Line Numbers
  1. SELECT  category.name AS 'Category Name', 
  2.         attribute.name AS 'Attribute Name'
  3. FROM re_attributeCategory AS category
  4. INNER JOIN re_attribute AS attribute ON attribute.categoryID = category.id
  5. INNER JOIN re_attributeID AS id ON id.attributeID = attribute.id
  6. WHERE id.mlsID = 555
  7. ORDER BY category.name ASC

Any suggestions would be appreciated.
Jan 24 '09 #1
0 1375

Sign in to post your reply or Sign up for a free account.

Similar topics

3
12871
by: Matt O'Donnell | last post by:
Does anyone know how I can 'join' the results of one SQL query to the bottom of another? Eg. I have two queries: 1. SELECT Name, Surname FROM People WHERE Surname = Smith NAME ...
4
4235
by: Job Lot | last post by:
Is there anyway of Joining two or more DataTable with similar structure? I have three DataTables with following structures Data, AmountB/F, Repayments, InterestCharged and AmountC/F i want...
0
1831
by: Gianfranco | last post by:
Hi I got a problem with 2 tables. I have a table, say A, with x records, coming from a make table query and a table, say B, with y records, coming from another make table query. I need to join...
0
1257
by: Norma | last post by:
I have 2 queries that pull attendance records depending on the type of attendance occurance, or Both queries are drawn off 1 table where the field will depict whether it is a punctuality or...
0
1252
by: dkintheuk | last post by:
Hi all, I'm trying to output a result set from some data as follows: I have raw data with the following columns Date, Country, System, ID,
10
25505
by: Captain Nemo | last post by:
Hi I'm working on an ASP project where the clients want to be able to effectively perform SELECT queries joining tables from two different databases (located on the same SQL-Server). Does...
12
5534
by: veaux | last post by:
Question about joins in queries. I have 2 tables with a field called "ID". Table 1 Rec1 = Jan12FredFlintstone Rec2 = Feb01WilmaRubble Table 2 Rec1 = Jan12BarneyRubble Rec2 = Mar03SamSlate
4
4605
by: jason.teen | last post by:
Hi, when i am joining on a Column of Text Type with one of Memo type the resulting entry has funny chinese characters! Has anyone else encountered this before? Is there a cure?? Cheers.
3
1560
by: nickvans | last post by:
Hello everyone, I am new to SQL Server, and am having trouble joining several SELECT statements together. I have three SQL Select statements that do separate count operations to get the status...
1
3400
by: bhavinnaik | last post by:
Hi I am new to the IT enviro...although i've used QSL query for a while now but on simple or single queries. Here is the problem... I've got two queries looking at a set of tables to extract the...
0
7040
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6905
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7041
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6736
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5331
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4772
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4478
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
2980
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
561
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.