You need to identify the tables for each of the columns that have the same name. You should also be using an IN statement and not = for the department.
I can’t test this since I don’t have your DB but you can try this:
$sql = $wpdb->get_results("SELECT * FROM " . $wpdb->prefix .
"dir_personnel as personnel where lname like '$search%' or fname like '$search%' or
extension like '$search%' or personnel.department IN (SELECT id FROM " . $wpdb->prefix .
"dir_departments as departments where departments.department like '$search%') order by lname");
Related Posts:
- How to display SQL query that ran in query?
- How to Use Wildcards in $wpdb Queries Using $wpdb->get_results & $wpdb->prepare?
- wpdb get posts by taxonomy SQL
- Multipart/formatted MySQL query problem
- WordPress creating excessive joins on meta_query with search
- cron job to auto delete posts of a specific post type older than x days
- Are database queries created using WordPress filters protected from SQL injection?
- Get posts by category with pure SQL query
- Custom query to get terms from post ids
- Get the timout value of a saved transient?
- Select query for a login
- What’s wrong with my $wpdb prepare?
- How do I see the mysql query generated by get_posts( $args )?
- sql select query in wordpress ‘page’ [closed]
- Select Query demand excesive resources [closed]
- problem with sql query in wordpress plugin
- Attempt to improve WP search, can someone check my SQL query?
- wpdb query problem to access previous 3 days posts
- I can’t figure out what’s wrong with this statement. $wpdb->query update
- Custom Query – Based on user input
- how to insert missing tags into the posts through mySQL?
- $wpdb->prepare affecting the query?
- WordPress SQL search, how to handle SQL Injection?
- exclude pingbacks from wordpress SQL query
- prepare function sql safe method
- WordPress SQL query to tag all posts containing a specific word on title
- Select column name dynamically mySQL Query
- How do I query for posts by custom meta and those that have been stickied?
- Change pure SQL database query to WordPress post query?
- Cannot get sql request from Query object?
- I want to get on those users their meta value are like “AGENT” .. but this query is not working
- Display data from phpMyAdmin with WordPress
- SQL to Query the db and return all posts and it’s metas
- SQL query to delete users with multiple meta keys and comments
- Speed up search query that searches in post meta?
- Are there any best practices for creating a Like/Favourite feature in WordPress using custom MySQL tables and without any plugins?
- Fastest and most efficient SQL query to check if UID exists
- How to make MySQL search queries with quotes
- How i make a custom sql query for Woocommerce
- $wpdb query for price in custom field value
- Run an update query in a function
- How to display a specific category using a custom Query in WordPress?
- Slow query when joining wp_posts with a lookup-table?
- Wpdb generates too many queries
- learn to run wpdb class
- SQL Query : how copy all tags of post into their post content in wordpress by sql query
- Where can I find the SQL to get the most used information by wordpress database?
- Custom Query for wp_posts using wp_postmeta
- 3 queries to update WordPress
- SQL conditional SELECT
- MySQL error: Unknown column in ‘where clause’
- Get Terms by IDs with IDs order
- Slow wp_enqueue_media()
- How to tell if $query_var isset?
- Sorting Grids with Essential Grid and Events Manger
- The use of including upgrade.php when building custom queries
- Does meta_query work within get_posts array?
- How to show more than 5 posts?
- WordPress Find Duplicate Post By Content
- WP Query Sort by meta value (date)
- how to query multiple categories in wordpress?
- Disable the MySQL query in the main query
- Update slug (URL) of pending posts via phpMyAdmin
- How can I get the query that would be run for the archive page?
- Query metas (and not : query posts by metas)
- where should I reset query after using get_results?
- Exclude featured image and custom field from this get_attachment query
- wpdb print all post meta
- Form and custom query problem
- Export Specific User data without plugin
- How to write: $wpdb->update having WHERE NOT value pair in the array
- Exclude all sticky posts front page twenty twelve
- wpdb COALESCE won’t work
- get csv of users with user_meta
- Query does not return content
- Parse query filter in wordpress and relation
- get posts by tag to showing in a widget
- Mysql query not working on WordPress 4.2.2
- List WordPress Post and Related Attachments outside of a post page
- How properly create a blog template for wordpress?
- Is there a way to add a link directly into this media query?
- Display latest post from WordPress Featured Category that is also in X,Y,or Z categories
- SQL query – get a featured image’s alt / alternative text
- Customising the default wordpress search functionality
- Question about of query
- Sort by postmeta on when searching
- Pulling an ACF into a query
- Using cron for multiple queries
- very slow wordpress query with default query
- Custom Query problem access the values
- Set posts per page for parent category and it’s all children
- Exclude sticky posts from query
- Rewrite Query_Var URL Parameter with Slug
- How to query different categories on index?
- Can’t See Media Queries with Inspect Tool [closed]
- Print data from wordpress sql query
- How do I troubleshoot Maximum execution time of 60 seconds exceeded in updating a Media File?
- update $wpdb one query
- Admin Post List table Query filtering “WHERE” for custom post type
- How to use a dynamic term id for the query block