473,672 Members | 3,354 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

select multiple columns from multiple tables with different number of columns

omerbutt
638 Contributor
hi there i have to select 7 columns from table1, 1 column from table2, and 1 column from tables3 and show the result but i am not getting it right the main thing that i am trying to achieve is that i am making a notice board in a community and i have to show the notices that are posted for the specific user by comparing the fields like GENDER AGE AND CITY that are given in the notice i have done it quiet right to some extent means if i have to compare only
age (between 19 and 26)
and
gender (Male only )
OR
gender(Female only)
but what if THE NOTICE IS ABOUT BOTH THE GENDERS MALE AND FEMALE then it creates a problem the
notice description, title ,notice gender,notice city ,notice start age, notice end age and notice expiry are comming from
notices table
and the members age is comming from the
member_profile table
and the gnder is comming from the
members table
iwrote the query
Expand|Select|Wrap|Line Numbers
  1. SELECT DISTINCT 
  2.     rage_notice.notice_startdate, 
  3.     rage_notice.notice_enddate, 
  4.     rage_notice.notice_id, 
  5.     rage_notice.member_id, 
  6.     rage_notice.notice_title, 
  7.     rage_notice.notice_description, 
  8.     rage_notice.notice_age_start, 
  9.     rage_notice.notice_age_end,
  10.     rage_notice.notice_sex, 
  11.     rage_notice.notice_country, 
  12.     rage_notice.notice_city,
  13.     rage_members_profile.members_profile_age,
  14.     rage_members.member_type 
  15. FROM rage_notice,rage_members_profile,rage_members 
  16. WHERE (rage_notice.notice_enddate >=  '$date' and rage_members_profile.member_id=$member_id) 
  17. AND rage_notice.member_id != $member_id 
  18. AND rage_members_profile.members_profile_age >= rage_notice.notice_age_start 
  19. AND rage_members_profile.members_profile_age <= rage_notice.notice_age_end 
  20. AND (rage_members.member_type=rage_notice.notice_sex) 
  21. ORDER BY rage_notice.notice_stamp desc
  22.  
this query works for the case if the notice posted is for the Males and it works perfect but when i try to add the rage_notice.not ice_sex='Both' with the following line @ very last line of the query (rage_members.m ember_type=rage _notice.notice_ sex || rage_notice.not ice_sex ='Both') it do picks up the exact records but shows those notices twice where gender='Both' although i am using distinct keyword but it will not work in three tables any suggesstions for that
thanks for any help in advance
regards,
omer
May 12 '08 #1
2 11429
BHTanna
31 New Member
Distinct key word work with n no of tables..

But i feel, your select statement has 2 fields (i.e member_type, sex), which i guess has 2 different values.. So, it is giving record twice when u add this extra condition. Remove either field...

Hope it works..
Aug 8 '08 #2
coolsti
310 Contributor
I am not going into detail at all in your query problem because I do not know the structure of the tables.

However, one thing I do note: You are joining three tables, yet you only show one equality between the tables in your where clause, in this case

[code]
AND (rage_members.m ember_type=rage _notice.notice_ sex)
[\code]

In general, if you are joining N tables, you need N-1 equalities between the tables. You are joining 3 tables so I would expect you need 2 equalities for a proper join.

This might be hidden by the fact that you use the Distinct keyword. I am just wondering if the missing equality will result in your query giving you the wrong results.
Aug 8 '08 #3

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

Similar topics

4
1371
by: Denis St-Michel | last post by:
Hello All, Hope some Guru will be able to help me with this. Let's take this example table A ------------------------------------------------------------------------------- id | TicketNo | evaluation | Username ------------------------------------------------------------------------------- 1 1 9 Jamie 2 1 8.5 ...
17
5010
by: kalamos | last post by:
This statement fails update ded_temp a set a.balance = (select sum(b.ln_amt) from ded_temp b where a.cust_no = b.cust_no and a.ded_type_cd = b.ded_type_cd and a.chk_no = b.chk_no group by cust_no, ded_type_cd, chk_no)
10
5619
by: serge | last post by:
Using "SELECT * " is a bad practice even when using a VIEW instead of a table? I have some stored procedures that are identical with the difference of one statement in the WHERE clause. If I create a single View and specify also in this View the WHERE clause that is common in these stored procedures, I will have the new stored procecures changed to be like:
6
26534
by: Terentius Neo | last post by:
Is it possible to combine (in DB2 UDB 8.1) a stored procedure and a select statement? I mean something like this: Select c.number, call procedure( c.number ) as list from table c With best regards
6
4840
by: jjturon | last post by:
Can anyone help me?? I am trying to pass a Select Query variable to a table using Dlookup and return the value to same select query but to another field. Ex. SalesManID SalesManName AT Alan Time
8
7249
by: carlospedr | last post by:
I have to insert data from about 30 tables into a single table (Users), to do so i used a cursor and a bit of dynamic sql, this should work fine if the tables have to do the select from had the same number of columns, how ever they don't. I only need the first 5 columns from each the table, in the case where they have more than the 5 i need for my 'Users' table i get this error: 'An explicit value for the identity column in table 'Users'...
4
2444
by: satish | last post by:
Values of two columns in two different tables--presentation using select Hi Everyone, i have two tables in the database . One is called address table and one is adressPhone Table. Below is the sample of those two tables
2
1577
by: jeffvh | last post by:
I have 2 tables related as: T1.KEY, T1.FIELD1, T1.FIELD2 T2.KEY, T2.FIELDA, T2.FIELDB T2.KEY, T2.FIELDA, T2.FIELDB T1.KEY = T2.KEY I want to return a SELECT as:
1
4776
by: NumberCruncher | last post by:
Hi All, I am struggling with setting up my first system of tables, forms,and reports, and could use your help! I am setting up a database to keep track of the production of a produced item. The item is a panel, with a specific texture. There are standard panels that are then produced in a limited number of specific textures. The number of panels/project varies, so I keep track of the actual number of panels per project with the count:...
0
8504
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8846
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8643
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6255
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5720
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4242
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4439
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2837
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1837
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.