473,409 Members | 1,935 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,409 software developers and data experts.

Help with SQL statement

Don
Hi folks

I wonder if someone could help me with a script I have been trying
unsuccessfully to write for a while now.

I have two tables - member_dest and member_det and have 3 search
criteria ie category, destination and gender. I have written the php
code to handle any combination of the 3 and produce $category, $dest
and $gender (some or all of which might be '%' ie wildcard. $category
and $gender can be found in member_det and $dest is from
member_destination.

Now I need to select data from both tables by searching the 3 criteria
ie in english something along the lines of the following -

Select * from both tables where member_det.category LIKE $category AND
member_det.gender LIKE $gender AND member_dest.destination LIKE $dest
Hope thats clear enough. Any help would be greatly appreciated.

Don

Jul 17 '05 #1
4 1260
On 5 Jan 2005 11:18:58 -0800, "Don" <in**@keyportmills.com> wrote:
I wonder if someone could help me with a script I have been trying
unsuccessfully to write for a while now.

I have two tables - member_dest and member_det and have 3 search
criteria ie category, destination and gender. I have written the php
code to handle any combination of the 3 and produce $category, $dest
and $gender (some or all of which might be '%' ie wildcard. $category
and $gender can be found in member_det and $dest is from
member_destination.

Now I need to select data from both tables by searching the 3 criteria
ie in english something along the lines of the following -

Select * from both tables
What relates the two tables together?
where member_det.category LIKE $category
Other than some quotes you're basically there, assuming you've escaped
$category appropriately.
AND
member_det.gender LIKE $gender AND member_dest.destination LIKE $dest


Similar to above.

--
Andy Hassall / <an**@andyh.co.uk> / <http://www.andyh.co.uk>
<http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
Jul 17 '05 #2
Don
Thanks Andy

member_id is the colum that relates both. I had the following query
working -

$query = 'SELECT member_hol_dest.member_id AS dest_id,
member_hol_details.member_id AS det_id from member_hol_dest,
member_hol_details WHERE member_hol_dest.dest LIKE "'.$dest.'" AND
member_hol_details.gender LIKE "'.$gender.'" AND
member_hol_details.category LIKE "'.$category.'"';
This worked but gave me an array that looked something like the
following:

============================
member_id | Member_id |
============================
1 | 1 |
1 | 2 |
2 | 1 |
2 | 2 |
| |
=============================

What I really wanted was a list of member_id's of a those who satisfy
any or all of the search criteria.

Cheers

Jul 17 '05 #3
Don wrote:
Thanks Andy

member_id is the colum that relates both. I had the following query
working -

$query = 'SELECT member_hol_dest.member_id AS dest_id,
member_hol_details.member_id AS det_id from member_hol_dest,
member_hol_details WHERE member_hol_dest.dest LIKE "'.$dest.'" AND
member_hol_details.gender LIKE "'.$gender.'" AND
member_hol_details.category LIKE "'.$category.'"';
This worked but gave me an array that looked something like the
following:

============================
member_id | Member_id |
============================
1 | 1 |
1 | 2 |
2 | 1 |
2 | 2 |
| |
=============================

What I really wanted was a list of member_id's of a those who satisfy
any or all of the search criteria.

Cheers


I would suggest using an explicit JOIN, that way you have a distinct
expression (the ON clause) that relates the two tables and another
distinct expression (the WHERE clause) for selection citeria. You
don't provide enough information to clearly understand the relationship
between the tables. I am assuming there is a many-to-one relationship
between member_hol_details and member_hol_dest here. Then, using an
explicit (INNER) JOIN:

SELECT member_hol_dest.member_id AS dest_id,
member_hol_details.member_id AS det_id
FROM member_hol_dest
INNER JOIN member_hol_details ON
member_hol_details.member_id=member_hol_dest.membe r_id
WHERE <condition 1>
AND/OR
<condition 2>
etc...

Hope this helps or at least doens't hurt...

NM

--
convert uppercase WORDS to single keystrokes to reply
Jul 17 '05 #4
Don
Excellent, I had an idea it was to do with joins but I dont have alot
of experience with them. I incorporated your script and it works
perfectly.

Thanks very much to both of you.

Don

Jul 17 '05 #5

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

Similar topics

46
by: Kingdom | last post by:
In my data base I have a list of componet types e.g. type A - I have 8 off - type B I have 12 off etc. I'm using Set objRS = objDC.Execute("Select DISTINCT Component_Type FROM Parts_Table") ...
6
by: Mark Reed | last post by:
Hi all, I am trying to learn a little about programming (I know next to nothing so far) and have found some code which hides the toolbars. However, this bit of code is a little too effective and...
8
by: drose0927 | last post by:
Please help! I can't get my program to exit if the user hits the Escape button: When I tried exit(EXIT_SUCCESS), it wouldn't compile and gave me this error: Parse Error, expecting `'}''...
5
by: Jesee | last post by:
I am reading Jeffrey Richter's book "Applied Microsoft .NET Framework programming",i came across "Exception handing". Page 405 says "If the stack overflow occurs within the CLR itself,your...
11
by: Scott C. Reynolds | last post by:
In VB6 you could do a SELECT CASE that would evaluate each case for truth and execute those statements, such as: SELECT CASE True case x > y: dosomestuff() case x = 5: dosomestuff() case y >...
2
by: Greg Corradini | last post by:
Hello All, A few weeks ago, I wrote two scripts using mx.ODBC on an Access DB. Among other things, both scripts create new tables, perform a query and then populate the tables with data in a...
6
by: redashley40 | last post by:
This is my first attempt in SQL and PreparedStatement I have add the PreparedStatement and I'm not to sure if I'm doing it correctly. When I do a test run on Choose 1 ,or 2 I get this error. Error...
2
by: rookiejavadude | last post by:
I'm have most of my java script done but can not figure out how to add a few buttons. I need to add a delete and add buttong to my existing java program. Not sure were to add it on how. Can anyone...
0
by: RCapps | last post by:
When running the below SQL Query I keep getting the following error: Server: Msg 4924, Level 16, State 1, Line 1 ALTER TABLE DROP COLUMN failed because column 'ContractDef' does not exist in table...
2
by: kya2 | last post by:
I am not able to create following store procedure. CREATE PROCEDURE DBSAMBA.InsertDeleteBatch(OUT norows INT ) RESULT SETS 1 LANGUAGE SQL BEGIN part1 DECLARE TOTAL_LEFT INT DEFAULT 0; ...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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
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
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
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
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,...
0
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...

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.