<?xml version="1.0"?>

<custom-sql>
	<sql id="com.liferay.portlet.bookmarks.service.persistence.BookmarksEntryFinder.countByFolderIds">
		<![CDATA[
			SELECT
				COUNT(*) AS COUNT_VALUE
			FROM
				BookmarksEntry
			WHERE
				[$FOLDER_ID$]
		]]>
	</sql>
	<sql id="com.liferay.portlet.bookmarks.service.persistence.BookmarksEntryFinder.countByGroupId">
		<![CDATA[
			SELECT
				COUNT(DISTINCT BookmarksEntry.entryId) AS COUNT_VALUE
			FROM
				BookmarksEntry
			INNER JOIN
				BookmarksFolder ON
					(BookmarksFolder.folderId = BookmarksEntry.folderId)
			WHERE
				(BookmarksFolder.groupId = ?)
		]]>
	</sql>
	<sql id="com.liferay.portlet.bookmarks.service.persistence.BookmarksEntryFinder.countByG_U">
		<![CDATA[
			SELECT
				COUNT(DISTINCT BookmarksEntry.entryId) AS COUNT_VALUE
			FROM
				BookmarksEntry
			INNER JOIN
				BookmarksFolder ON
					(BookmarksFolder.folderId = BookmarksEntry.folderId)
			WHERE
				(BookmarksFolder.groupId = ?) AND
				(BookmarksEntry.userId = ?)
		]]>
	</sql>
	<sql id="com.liferay.portlet.bookmarks.service.persistence.BookmarksEntryFinder.findByGroupId">
		<![CDATA[
			SELECT
				DISTINCT {BookmarksEntry.*}
			FROM
				BookmarksEntry
			INNER JOIN
				BookmarksFolder ON
					(BookmarksFolder.folderId = BookmarksEntry.folderId)
			WHERE
				(BookmarksFolder.groupId = ?)
			ORDER BY
				BookmarksEntry.modifiedDate DESC
		]]>
	</sql>
	<sql id="com.liferay.portlet.bookmarks.service.persistence.BookmarksEntryFinder.findByG_U">
		<![CDATA[
			SELECT
				DISTINCT {BookmarksEntry.*}
			FROM
				BookmarksEntry
			INNER JOIN
				BookmarksFolder ON
					(BookmarksFolder.folderId = BookmarksEntry.folderId)
			WHERE
				(BookmarksFolder.groupId = ?) AND
				(BookmarksEntry.userId = ?)
			ORDER BY
				BookmarksEntry.modifiedDate DESC
		]]>
	</sql>
</custom-sql>