473,503 Members | 1,697 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Left Outer Join with Where clause

155 New Member
I can't seem to get this working:

Expand|Select|Wrap|Line Numbers
  1. $query = "SELECT c.c_id,c.c_name, COUNT( p.recipe_title ) as theCount
  2. FROM new_recipe_cat AS c
  3. LEFT OUTER JOIN new_recipes AS p ON c.c_id = p.c_id
  4. WHERE (c_id==11 && c_id==12 && c_id==13 && c_id==14
  5. && c_id==15 && c_id==16 && c_id==17 && c_id==22
  6. && c_id==23)
  7. AND r_allow=1
  8. GROUP BY c.c_name";
The where clause isn't working and it's throwing an error: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource

Any ideas on how I can fix this?

Thanks
Feb 5 '10 #1
4 2265
Markus
6,050 Recognized Expert Expert
Get the error string from mysql by using mysql_error().
Feb 5 '10 #2
Atli
5,058 Recognized Expert Expert
Yep, you should always check mysql_error() when there is an error in a MySQL query.

However, I would guess that your problem is with the "c_id==11" checks. There is only supposed to be a single "=" in there. SQL does not use two "=" chars like most programming languages do.
Feb 5 '10 #3
DavidPr
155 New Member
However, I would guess that your problem is with the "c_id==11" checks. There is only supposed to be a single "=" in there. SQL does not use two "=" chars like most programming languages do.
Right, I was working with an if clause earlier and the two == was stuck in my mind.

I tried a few various ways of working the WHERE clause but it just wasn't doing it for me. I used the mysql_error, but it wasn't throwing an error. It just didn't return anything or something that I didn't want. Oh well, I just went back to using an if clause. It list what I want just not in alphabetical order.

I appreciate all the help. Thanks.

DavidPr
Feb 9 '10 #4
Atli
5,058 Recognized Expert Expert
No problem.

One thing that I don't get though. You used && (and) between all those checks. Are you sure you didn't mean to use || (or)? - Using && your c_id would have had to match all of the numbers per row to return it (which doesn't make sense. Presumably it only has one value).

You could try the IN() function. - Something like:
Expand|Select|Wrap|Line Numbers
  1. WHERE c_id IN(11, 12, 13, 14, 15, 16, 17, 22, 23)
Feb 9 '10 #5

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

Similar topics

3
2273
by: sks | last post by:
I have a Product table, a Categories table and a join table that contains product to category mappings (each product can be in many categories) CREATE TABLE categories ( id bigint(20) unsigned...
1
4203
by: Steve | last post by:
I have a SQL query I'm invoking via VB6 & ADO 2.8, that requires three "Left Outer Joins" in order to return every transaction for a specific set of criteria. Using three "Left Outer Joins"...
3
23074
by: Ian Boyd | last post by:
i know nothing about DB2, but i'm sure this must be possible. i'm trying to get a client to create a view (which it turns out is called a "Logical" in DB2). The query needs a LEFT OUTER JOIN, but...
5
2269
by: Dev | last post by:
Hello all, I need to do a left out join where a.field1 ilike %b.field2% But I can not figure out the exact syntax to using the ilike in the join? ----------
2
3128
by: tricard | last post by:
Good day all, I have a large outer joined query that I want to have some criteria. The select query is gathering all part numbers from tblPartNumbers, left joining to tblPartNumberVendor (since...
1
4555
by: Eitan M | last post by:
Hello, I want to do select like this : select t1.col_2 from table_1 t1, table_2 t2 where t1.col_1 = t2.col_1 (+) The above is correct syntax for Oracle. What is the correct syntax for...
9
9201
by: shanevanle | last post by:
I have two tables that are pretty big. I need about 10 rows in the left table and the right table is filtered to 5 rows as well. It seems when I join the tables in the FROM clause, I have to...
5
15482
by: Sascha.Moellering | last post by:
Hi, I receive the error code SQL0338N if I try to compile this statement (part of the statement): .... left outer join lateral (SELECT * FROM LIZSYSABA.VWZL0359TBS WHERE tbs_name = CASE WHEN...
3
19216
by: pbassutti | last post by:
Hello, I'm trying to link two tables... one for Employees and the other for Timecards I need to get a list of employees that do not have timecards on an SPECIFIC DATE I tried the follonwing
9
11908
by: shapper | last post by:
Hello, I am used to SQL but I am starting to use LINQ. How can I create Left, Right and Inner joins in LINQ? How to distinguish the different joins? Here is a great SQL example:...
0
7199
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
7074
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
7273
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
7322
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...
1
6982
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...
1
5000
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
3161
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...
0
3150
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1501
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 ...

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.