473,394 Members | 1,765 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Simple 3 table query failing.

I have a database with three tables
tbl_listings - listings of houses on for sale

tbl_intersted - table which tracks if a user is interested in the
listing, it has two columns mls(the key for tbl_listings) and user(user
login)

tbl_review - table which trackes if a user has reviewed the listing.
Like tbl_interested it has two columns (the key for tbl_listings) and
user(user login)

How can I create a query on tbl_listings for reocords reviewed by one
user?

I am trying to create a query for listings that are revied by user
userid. I am using the query below. It works fine unless there is a
record in tbl_interested for a differnt user.

In reality I am calling this query from the web. On the website I have
an intersted dropdown with the choices All, interested, not interested.
The website also has a reviewed dropdown with all, reviewed and not
reviewed.

I am using the query below as a starting point. my query works fine
with one user, but if a user2 enters a record in tbl_intersted it
throws off the left join for user1. How can I fix this?
SELECT COUNT(B.reviewed) AS review_count,Count(B.mls) as mls_count,
A.mls,
FROM mls.tbl_listings A
LEFT OUTER JOIN mls.tbl_review B ON A.mls = B.mls
LEFT OUTER JOIN mls.tbl_interested D ON A.mls = D.mls

where (B.reviewed = 'userid') and ((D.interested is null) or
(D.interested = 'userid'))

----
My query works fine if there is one user, however once user2 reviews a
record from tbl_listing user1

Aug 25 '05 #1
2 1427
Your description is a little unclear (to me, at least), so perhaps you
could post a short test case, to show exactly what your tables look
like and what results you require?

http://www.aspfaq.com/etiquette.asp?id=5006

Simon

Aug 25 '05 #2
On 24 Aug 2005 21:52:06 -0700, td*******@yahoo.com wrote:
I have a database with three tables
tbl_listings - listings of houses on for sale

tbl_intersted - table which tracks if a user is interested in the
listing, it has two columns mls(the key for tbl_listings) and user(user
login)

tbl_review - table which trackes if a user has reviewed the listing.
Like tbl_interested it has two columns (the key for tbl_listings) and
user(user login)

How can I create a query on tbl_listings for reocords reviewed by one
user?

I am trying to create a query for listings that are revied by user
userid. I am using the query below. It works fine unless there is a
record in tbl_interested for a differnt user.

In reality I am calling this query from the web. On the website I have
an intersted dropdown with the choices All, interested, not interested.
The website also has a reviewed dropdown with all, reviewed and not
reviewed.

I am using the query below as a starting point. my query works fine
with one user, but if a user2 enters a record in tbl_intersted it
throws off the left join for user1. How can I fix this?
SELECT COUNT(B.reviewed) AS review_count,Count(B.mls) as mls_count,
A.mls,
FROM mls.tbl_listings A
LEFT OUTER JOIN mls.tbl_review B ON A.mls = B.mls
LEFT OUTER JOIN mls.tbl_interested D ON A.mls = D.mls

where (B.reviewed = 'userid') and ((D.interested is null) or
(D.interested = 'userid'))

----
My query works fine if there is one user, however once user2 reviews a
record from tbl_listing user1


Hi tdmailbox,

I agree with Simon: complete table definitions, sample data and expected
output make helping you a lot easier. Based on this message, the best I
can do is a guess:

SELECT COUNT(B.reviewed) AS review_count,
COUNT(B.mls) AS mls_count,
A.mls,
FROM mls.tbl_listings AS A
LEFT OUTER JOIN mls.tbl_review AS B
ON A.mls = B.mls
AND B.reviewed = 'userid'
LEFT OUTER JOIN mls.tbl_interested AS D
ON A.mls = D.mls
AND (D.interested = 'userid' OR D.interested IS NULL)

By the way, I recommend you rename your tables: get rid of the tbl_
prefix (a table is the only data structure allowed in a database, so
it's useless) and for the main table: name it after what it contains,
not after how it's presented.

* tbl_listings ==> HousesAvailable
* tbl_interested ==> Interests
* tbl_review ==> Reviews

The names may not be optimal (English is not my native language), but
you get the idea.

Best, Hugo
--

(Remove _NO_ and _SPAM_ to get my e-mail address)
Aug 25 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Ed_No_Spam_Please_Weber | last post by:
Hello All & Thanks in advance for your help! Background: 1) tblT_Documents is the primary parent transaction table that has 10 fields and about 250,000 rows 2) There are 9 child tables with...
1
by: Juris Krumins | last post by:
Couple a weeks ago (19.08.03 Subject: Temporaty tables) I've posted message with question about errors I'm getting while using create temporaty table command. So I'm start digging in src code as...
4
by: jane | last post by:
HI, I try to create summary table like following: create table summary (a int, b int, c int) (select a.aa, b.bb, b.cc from table_a a ,table_b b where a.key=b.key) data initially deferred...
5
by: deko | last post by:
How to run action query against linked table? I have an Access 2003 mdb with an Excel 2003 Workbook as a linked table. When I attempt to run an action query against the linked table I get this...
1
by: Old Timer | last post by:
I wish to type in a number in my "Code" field, for instance 1060, I then wish the number 1060 to trigger an event that will fill in the next field (township field) For instance, 1060 brings up and...
4
by: frank | last post by:
I posted a question before (to too many groups) and this time I am sending to this group only. I have a quick script as seen below, the file_list table has a unique field called file_name. The...
5
by: phillip.s.powell | last post by:
$sql = "SELECT IF((SHOW TABLES LIKE '$subselectTableName'), count(*), NULL) AS numRows FROM $subselectTableName"; I am trying to write a SQL statement that will tell me if a table exists or not,...
4
by: sandeep.iitk | last post by:
Hi, One query is failing on the database and its a long query which was running fine earlier. One possible reason we can think of is increase in data in tables in query. It is failing with...
0
by: sandymbm | last post by:
Hi, One query is failing on the database and its a long query which was running fine earlier. One possible reason we can think of is increase in data in tables in query. It is failing with...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...

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.