The SitePoint Forums have moved.

You can now find them here.
This forum is now closed to new posts, but you can browse existing content.
You can find out more information about the move and how to open a new account (if necessary) here.
If you get stuck you can get support by emailing forums@sitepoint.com

If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Hybrid View

sql question from a nOOb

I've managed to get the following code to do 99% of what I want it to:

SELECT tbl3.col1, tbl3.col11, tbl3.col2, tbl3.col3, tbl3.col4, tbl3.col5, tbl3.col6, tbl3.col7, tbl3.col8, tbl3.col13
FROM tbl3
WHERE ((tbl3.col13 = 1) AND ((tbl3.col11 = colcheck) AND (tbl3.col2 LIKE '%colname%' AND tbl3.col6 LIKE '%colcity%' AND tbl3.col7 LIKE '%colstate%' AND tbl3.col4 LIKE '%coladdress%' AND tbl3.col8 LIKE '%colzip%')))
ORDER BY tbl3.col2 ASC

It for an advanced search form. col13 is set manually in the code, col11 is a radio button, and the rest of the fields are optional. It's for finding contacts in a table. I have colname which is the company name, but also a want to check it against col3 (not only col2). Same with coladdress, I'd like to check it against col5 (not only col4). Does anyone know how to accomplish this?

Thanks I gave your code a try and it worked perfectly. But I tried adding a few fields on the end of it and it doesn't work at all now. Everything looks ok to me, not sure what's wrong. Does the order matter at all?

SELECT tbl3.col1, tbl3.col11, tbl3.col2, tbl3.col3, tbl3.col4, tbl3.col5, tbl3.col6, tbl3.col7, tbl3.col8, tbl3.col13, tbl3.col17, tbl3.col18, tbl3.col19
FROM tbl3
WHERE tbl3.col13 = 1 and tbl3.col11 = colcheck and (tbl3.col2 like '%colname%' or tbl3.col3 like '%colname%') and tbl3.col6 like '%colcity%' and tbl3.col7 like '%colstate%' and (tbl3.col4 like '%coladdress%' or tbl3.col5 like '%coladdress%') and tbl3.col8 like '%colzip%' and tbl3.col17 like '%colrisk%' and tbl3.col18 like '%colfedid%' and tbl3.col19 like '%colclientid%'
ORDER BY tbl3.col2 ASC