Jump to content

Cannot figure OR search right


Voodoo Jai

Recommended Posts

Hi all

I am wanting to search two fields for a LOCATION ("Leeds")  that hold the name of a location. But only get an AND search result.

 

Sample data

ID  Field 1          Field2

1    Leeds          Armley

2    Leeds          Leeds

3    Crossgates    Leeds

 

the search only returns ID 2 not all of them, I need to find all the fields that contain "Leeds".

 

Here is the statement I am using

 

SELECT t.`TakeawayID`, t.`Takeaway_Name`, t.`Line1`, `Location`, C.`City`, t.`Post_Code`
FROM takeaway t, location l, City C
WHERE (Location = "Leeds" OR t.City = "Leeds") AND t.`LocationID`= l.`Town_CityID` AND t.`City`= C.`CityID`
ORDER BY `Location`;

Link to comment
Share on other sites

First table structure

Takeaway table

+-----------------+---------------------+------+-----+-------------------+----------------+
| Field                 | Type                       | Null   | Key | Default                 | Extra               |
+-----------------+---------------------+------+-----+-------------------+----------------+
| TakeawayID       | int(10) unsigned       | NO    | PRI  | NULL                    | auto_increment |
| Takeaway_Name | varchar(100)            | NO   |        | Takeaway name     |                |
| Line1                | varchar(50)              | NO   |        | Line 1                   |                |
| Line2                | varchar(50)              | YES  |        | NULL                   |                |
| LocationID         | int(10) unsigned        | NO   | MUL | 0                        |                |
| City                  | int(10) unsigned        | NO   | MUL | 0                        |                |
+-----------------+---------------------+------+-----+-------------------+----------------+

Second table

Location table

+-------------------+------------------+------+-----+-------------------+----------------+
| Field                    | Type             | Null | Key | Default           | Extra          |
+-------------------+------------------+------+-----+-------------------+----------------+
| Town_CityID         | int(10) unsigned | NO   | PRI | NULL              | auto_increment |
| Location               | varchar(45)      | NO   | UNI |                   |                |
| CountyID              | int(10) unsigned | YES  | MUL | NULL              |                |
| ts                       | timestamp        | NO   |     | CURRENT_TIMESTAMP |                |
+-------------------+------------------+------+-----+-------------------+----------------+

 

Third table

City table

+--------+------------------+------+-----+---------------------+----------------+
| Field      | Type                 | Null    | Key | Default                    | Extra          |
+--------+------------------+------+-----+---------------------+----------------+
| CityID   | int(10) unsigned   | NO    | PRI  | NULL                       | auto_increment |
| City      | varchar(45)         | NO    | UNI |                                |                |
| ts         | timestamp          | NO     |       | 0000-00-00 00:00:00 |                |
+--------+------------------+------+-----+---------------------+----------------+

 

I am trying to search for a location that could be in either the

 

takeaway table

locationID or city field.

 

using the details of the location to search for from the

city table and Location table.

I have missed out some of the field in the takeaway table for clarity.

Link to comment
Share on other sites

I am serching one table but I want to find all rows with either a specific value in:

 

FIELD-A or FIELD-B

or in:

FIELD-A and FIELD-B

 

So Sample data that searches for "LEEDS"

 

ID  Field 1          Field2

1    Leeds          Armley

2    Leeds          Leeds

3    Crossgates    Leeds

 

Much appreciate your time to help me

 

VoodooJai

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.